For loop to generate mean for each measurement by sex
0
0
Entering edit mode
3.4 years ago
selplat21 ▴ 20
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 • 586 views
ADD COMMENT
1
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 2710 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6