[R] Coefficient of Variation, NA, Aggregate

Amanda Jones akjones82 at gmail.com
Mon Nov 19 22:01:44 CET 2012


Hello helpers,

I have a two part issue. FIRSTLY, I am attempting to write a function
for coefficient of variation, using

> co.var <- function(rowleyi) ( 100*sd(rowleyi)/mean(rowleyi) )  #where rowleyi is my data set, which has multiple columns and rows of data.

This is not working because some of my columns have NAs. When I try to use

> co.var(rowleyi$TL, na.rm=TRUE)  #where TL is one of my column names, it gives me an error message:

Error in co.var(rowleyi$TL, na.rm = TRUE) :
  unused argument(s) (na.rm = TRUE)

I do not know what this means. How can I get this function to work?
SECONDLY, how can I then get that function to work within an
aggragate? Do I still use

>aggregate(. ~ subspecies, data = rowleyi, CV, na.rm=TRUE) #where subspecies is the header for rows? This has worked for mean, std.error, sd, etc.

Thank you!
Amanda Jones



More information about the R-help mailing list