EDIT: Should have specified R 4.0.2 in RStudio 1.2.5033, dplyr 1.0.0
I am trying to group a dataframe by a single numeric variable (V34 in the below) and take group means on all other variables using summarize via sapply.
I get a warning that "group_by_" (note underscores) does not have a method to apply to class "character." I also get a note that group_by_ is deprecated in favor of group_by. This is confusing me for at least two reasons: I specified group_by, not group_by_, and none of the variables in the dataframe are of class character. A reprex follows.
I appreciate any help!
Pat
library("dplyr")
fakedata <- as.data.frame(matrix(data=c(-1, -1, 1954, 2.22, 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 614,
1 , 0 , 1950, 1.87, 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 1 , 0 , 0 , 1 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 660,
-1, -1, 1949, 1.56, 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 1 , 600,
1 , 0 , 1958, 1.05, 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 , 612,
-1, -1, 1959, 1.51, 1 , 0 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 660 ),
nrow=5,ncol=34,byrow=TRUE))
gmvreprex <- function(x,df) {
grpmn <- df %>% group_by(df$V34) %>%
dplyr::summarize(mean=mean(x))
}
sapply(fakedata,gmvreprex,"fakedata")