I would like to create the number of rows by group, whereby the groups are defined using all the variables in the dataframe.
Here are a few methods that I have tried, using the available starwars dataset as an example:
library(dplyr)
myData <- starwars %>% select(skin_color, gender, species)
# Method 1: using add_count
myData %>%
add_count(1:ncol(myData))
# Method 2: using aggregate
aggregate(. ~ 1:ncol(myData), data = myData, FUN = function(x){NROW(x)})
Both of which give an error that the length is incorrect. I suspect that I am using the wrong syntax. Is there a proper syntax to capture all the columns in my dataframe without having to type all of them, so that add_count and aggregate could produce the desired result?