Error in aggregate.formula - argument 'x' is missing What does this mean?

aggregate(formula = age ~ sex,
data = pirates,
FUN = mean)

Your use of the function looks correct. Please post the output of

dput(pirates)

or, if that is too big

dput(head(pirates,30))

Put a line with three back ticks just before and after the pasted output, like this
```
output of dput()
```

structure(list(id = 1:30, sex = c("male", "male", "male", "female", 
"female", "male", "female", "female", "female", "male", "female", 
"male", "female", "male", "female", "female", "male", "female", 
"female", "male", "male", "female", "male", "male", "male", "female", 
"male", "male", "female", "female"), age = c(28, 31, 26, 31, 
41, 26, 31, 31, 28, 30, 25, 20, 24, 26, 45, 40, 21, 30, 35, 26, 
22, 34, 23, 12, 35, 26, 15, 30, 17, 26), height = c(173.11, 209.25, 
169.95, 144.29, 157.85, 190.2, 158.05, 172.52, 164.57, 183.52, 
162.49, 163.65, 171.04, 177.99, 167.65, 165.1, 177.52, 158.3, 
173.07, 175.45, 187.83, 179.06, 158.66, 175.29, 187.48, 153.54, 
171.48, 177.04, 145.98, 134.87), weight = c(70.5, 105.6, 77.1, 
58.5, 58.4, 85.4, 59.6, 74.5, 68.7, 84.7, 63.5, 70, 72.6, 78.2, 
65.4, 65.7, 72.7, 65.6, 72.8, 69, 85.8, 82.1, 53.5, 83, 85.6, 
54.6, 66, 71.9, 57.4, 37.9), headband = c("yes", "yes", "yes", 
"no", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", 
"yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", 
"no", "yes", "yes", "yes", "yes", "no", "yes", "yes", "yes"), 
    college = c("JSSFP", "JSSFP", "CCCC", "JSSFP", "JSSFP", "CCCC", 
    "JSSFP", "JSSFP", "JSSFP", "JSSFP", "CCCC", "CCCC", "CCCC", 
    "CCCC", "JSSFP", "JSSFP", "CCCC", "JSSFP", "JSSFP", "CCCC", 
    "CCCC", "JSSFP", "CCCC", "CCCC", "JSSFP", "CCCC", "CCCC", 
    "JSSFP", "CCCC", "CCCC"), tattoos = c(9, 9, 10, 2, 9, 7, 
    9, 5, 12, 12, 10, 14, 8, 9, 14, 8, 11, 7, 7, 14, 10, 5, 13, 
    10, 10, 10, 2, 15, 14, 12), tchests = c(0, 11, 10, 0, 6, 
    19, 1, 13, 37, 69, 1, 5, 6, 12, 70, 3, 3, 107, 75, 30, 11, 
    13, 11, 3, 18, 10, 2, 15, 1, 44), parrots = c(0, 0, 1, 2, 
    4, 0, 7, 7, 2, 4, 3, 3, 0, 3, 0, 1, 0, 3, 14, 3, 6, 4, 1, 
    2, 1, 3, 0, 4, 1, 10), favorite.pirate = c("Jack Sparrow", 
    "Jack Sparrow", "Jack Sparrow", "Jack Sparrow", "Hook", "Jack Sparrow", 
    "Blackbeard", "Hook", "Anicetus", "Jack Sparrow", "Blackbeard", 
    "Jack Sparrow", "Lewis Scot", "Jack Sparrow", "Hook", "Hook", 
    "Jack Sparrow", "Blackbeard", "Hook", "Jack Sparrow", "Jack Sparrow", 
    "Edward Low", "Edward Low", "Jack Sparrow", "Jack Sparrow", 
    "Blackbeard", "Jack Sparrow", "Edward Low", "Hook", "Edward Low"
    ), sword.type = c("cutlass", "cutlass", "cutlass", "scimitar", 
    "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", 
    "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", "scimitar", 
    "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", 
    "cutlass", "cutlass", "sabre", "cutlass", "banana", "cutlass", 
    "cutlass", "cutlass"), eyepatch = c(1, 0, 1, 1, 1, 1, 0, 
    1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 
    1, 1, 0, 1), sword.time = c(0.58, 1.11, 1.44, 36.11, 0.11, 
    0.59, 3.01, 0.06, 0.74, 0.71, 0.78, 0.47, 0.53, 1.33, 0.33, 
    27.56, 0.33, 1.55, 0.72, 0.4, 0.5, 0.03, 0.02, 0.14, 11.23, 
    1.1, 44.74, 0.35, 0.18, 0.59), beard.length = c(16, 21, 19, 
    2, 0, 17, 1, 1, 1, 25, 1, 27, 0, 19, 0, 1, 20, 0, 0, 27, 
    12, 2, 29, 24, 17, 0, 18, 29, 0, 1), fav.pixar = c("Monsters, Inc.", 
    "WALL-E", "Inside Out", "Inside Out", "Inside Out", "Monsters University", 
    "Cars", "Inside Out", "Toy Story 3", "Monsters University", 
    "Inside Out", "Monsters, Inc.", "Monsters, Inc.", "Inside Out", 
    "Monsters University", "The Incredibles", "Finding Nemo", 
    "Monsters, Inc.", "Finding Nemo", "WALL-E", "Monsters, Inc.", 
    "Ratatouille", "Finding Nemo", "Up", "Inside Out", "Inside Out", 
    "Inside Out", "Inside Out", "Finding Nemo", "Monsters University"
    ), grogg = c(11, 9, 7, 9, 14, 7, 9, 12, 16, 9, 7, 8, 12, 
    7, 9, 10, 15, 8, 11, 10, 6, 8, 13, 8, 2, 9, 10, 15, 11, 2
    )), row.names = c(NA, 30L), class = "data.frame")

Using the data you posted, I do not get any error. Does it work for you?

pirates <- structure(list(id = 1:30, 
                          sex = c("male", "male", "male", "female", 
                                  "female", "male", "female", "female", "female", "male", "female", 
                                  "male", "female", "male", "female", "female", "male", "female", 
                                  "female", "male", "male", "female", "male", "male", "male", "female", 
                                  "male", "male", "female", "female"), 
                          age = c(28, 31, 26, 31, 
                                  41, 26, 31, 31, 28, 30, 25, 20, 24, 26, 45, 40, 21, 30, 35, 26, 
                                  22, 34, 23, 12, 35, 26, 15, 30, 17, 26), 
                          height = c(173.11, 209.25, 
                                     169.95, 144.29, 157.85, 190.2, 158.05, 172.52, 164.57, 183.52, 
                                     162.49, 163.65, 171.04, 177.99, 167.65, 165.1, 177.52, 158.3, 
                                     173.07, 175.45, 187.83, 179.06, 158.66, 175.29, 187.48, 153.54, 
                                     171.48, 177.04, 145.98, 134.87), 
                          weight = c(70.5, 105.6, 77.1, 
                                     58.5, 58.4, 85.4, 59.6, 74.5, 68.7, 84.7, 63.5, 70, 72.6, 78.2, 
                                     65.4, 65.7, 72.7, 65.6, 72.8, 69, 85.8, 82.1, 53.5, 83, 85.6, 
                                     54.6, 66, 71.9, 57.4, 37.9), 
                          headband = c("yes", "yes", "yes", 
                                       "no", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", 
                                       "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", "yes", 
                                       "no", "yes", "yes", "yes", "yes", "no", "yes", "yes", "yes"), 
                          
                          college = c("JSSFP", "JSSFP", "CCCC", "JSSFP", "JSSFP", "CCCC", 
                                      "JSSFP", "JSSFP", "JSSFP", "JSSFP", "CCCC", "CCCC", "CCCC", 
                                      "CCCC", "JSSFP", "JSSFP", "CCCC", "JSSFP", "JSSFP", "CCCC", 
                                      "CCCC", "JSSFP", "CCCC", "CCCC", "JSSFP", "CCCC", "CCCC", 
                                      "JSSFP", "CCCC", "CCCC"), 
                          tattoos = c(9, 9, 10, 2, 9, 7, 
                                      9, 5, 12, 12, 10, 14, 8, 9, 14, 8, 11, 7, 7, 14, 10, 5, 13, 
                                      10, 10, 10, 2, 15, 14, 12), 
                          tchests = c(0, 11, 10, 0, 6, 
                                      19, 1, 13, 37, 69, 1, 5, 6, 12, 70, 3, 3, 107, 75, 30, 11, 
                                      13, 11, 3, 18, 10, 2, 15, 1, 44), 
                          parrots = c(0, 0, 1, 2, 
                                      4, 0, 7, 7, 2, 4, 3, 3, 0, 3, 0, 1, 0, 3, 14, 3, 6, 4, 1, 
                                      2, 1, 3, 0, 4, 1, 10), 
                          favorite.pirate = c("Jack Sparrow", 
                                              "Jack Sparrow", "Jack Sparrow", "Jack Sparrow", "Hook", "Jack Sparrow", 
                                              "Blackbeard", "Hook", "Anicetus", "Jack Sparrow", "Blackbeard", 
                                              "Jack Sparrow", "Lewis Scot", "Jack Sparrow", "Hook", "Hook", 
                                              "Jack Sparrow", "Blackbeard", "Hook", "Jack Sparrow", "Jack Sparrow", 
                                              "Edward Low", "Edward Low", "Jack Sparrow", "Jack Sparrow", 
                                              "Blackbeard", "Jack Sparrow", "Edward Low", "Hook", "Edward Low"
                          ), 
                          sword.type = c("cutlass", "cutlass", "cutlass", "scimitar", 
                                         "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", 
                                         "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", "scimitar", 
                                         "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", "cutlass", 
                                         "cutlass", "cutlass", "sabre", "cutlass", "banana", "cutlass", 
                                         "cutlass", "cutlass"), 
                          eyepatch = c(1, 0, 1, 1, 1, 1, 0, 
                                       1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 
                                       1, 1, 0, 1), 
                          sword.time = c(0.58, 1.11, 1.44, 36.11, 0.11, 
                                         0.59, 3.01, 0.06, 0.74, 0.71, 0.78, 0.47, 0.53, 1.33, 0.33, 
                                         27.56, 0.33, 1.55, 0.72, 0.4, 0.5, 0.03, 0.02, 0.14, 11.23, 
                                         1.1, 44.74, 0.35, 0.18, 0.59), 
                          beard.length = c(16, 21, 19, 
                                           2, 0, 17, 1, 1, 1, 25, 1, 27, 0, 19, 0, 1, 20, 0, 0, 27, 
                                           12, 2, 29, 24, 17, 0, 18, 29, 0, 1), 
                          fav.pixar = c("Monsters, Inc.", 
                                        "WALL-E", "Inside Out", "Inside Out", "Inside Out", "Monsters University", 
                                        "Cars", "Inside Out", "Toy Story 3", "Monsters University", 
                                        "Inside Out", "Monsters, Inc.", "Monsters, Inc.", "Inside Out", 
                                        "Monsters University", "The Incredibles", "Finding Nemo", 
                                        "Monsters, Inc.", "Finding Nemo", "WALL-E", "Monsters, Inc.", 
                                        "Ratatouille", "Finding Nemo", "Up", "Inside Out", "Inside Out", 
                                        "Inside Out", "Inside Out", "Finding Nemo", "Monsters University"
                          ), 
                          grogg = c(11, 9, 7, 9, 14, 7, 9, 12, 16, 9, 7, 8, 12, 
                                    7, 9, 10, 15, 8, 11, 10, 6, 8, 13, 8, 2, 9, 10, 15, 11, 2
                          )), 
                     row.names = c(NA, 30L), class = "data.frame")

aggregate(formula = age ~ sex,
          data = pirates,
          FUN = mean)
#>      sex      age
#> 1 female 30.93333
#> 2   male 24.73333

Created on 2022-07-15 by the reprex package (v2.0.1)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.