Question: For loop to generate mean for each measurement by sex
gravatar for selplat21
6 weeks ago by
selplat2120 wrote:
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(! & !  %>% 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.

bioinformatics R • 114 views
ADD COMMENTlink modified 6 weeks ago • written 6 weeks ago by selplat2120

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

ADD REPLYlink written 6 weeks ago by rpolicastro3.1k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 912 users visited in the last hour