This is a test version of Biostars. For the public version, visit https://www.biostars.org.
For loop to generate mean for each measurement by sex
Phenotypes <- c("exposed_culman", "bill_width", "BLML", "LBL", "LW", "bill_curvature", "wing_chord", "body_length", "bill_depth","WEIGHT","profile_PC1","profile_PC2","profile_PC3","profile_PC4", "profile_PC5","dorsal_PC1","dorsal_PC2","dorsal_PC3","dorsal_PC4","dorsal_PC5")

names(Phenotypes) <- c("Exposed Culmen", "Culmen Width", "Body Length (No Culmen)", "Culmen Length to Body Length Ratio", "Culmen Length to Width Ratio", "Culmen Curvature", "Wing Chord", "Body Length", "Culmen Depth","Weight","Profile PC1","Profile PC2","Profile PC3","Profile PC4","Profile PC5", "Dorsal PC1","Dorsal PC2","Dorsal PC3","Dorsal PC4","Dorsal PC5")

for (i in Phenotypes){mu <- Anna %>% filter(!is.na(i) & !is.na(sex))  %>% group_by(sex) %>% summarise(grp.mean = mean(i))}

I can't seem to get the following for loop to group means by sex. I am consistently getting the following error:

Warning message:
In mean.default(i) : argument is not numeric or logical: returning NA

In case someone mentions that mu will be overwritten for each phenotype, I have additional arguments in the for loop I did not include here, but the error is only for the code shown above.

The list of phenotypes are the names of the columns in my dataframe.

r

You don't have any numeric values to get the mean of in your example data.

0 answers

No answers yet.

Log in to answer this question.