I am a new R user and want to make a line chart using stdwith ggplot. To do this, I use the function summarySE.
vrn1_summary<-summarySE(data,measurevar = "vrn1",groupvars = c("genotype","treatment","time"))
Since I cannot perform my own function, I copied the following from the R Cookbook:
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
conf.interval=.95, .drop=TRUE) {
library(plyr)
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na(x))
else length(x)
}
datac <- ddply(data, groupvars, .drop=.drop,
.fun = function(xx, col) {
c(N = length2(xx[[col]], na.rm=na.rm),
mean = mean (xx[[col]], na.rm=na.rm),
sd = sd (xx[[col]], na.rm=na.rm)
)
},
measurevar
)
datac <- rename(datac, c("mean" = measurevar))
datac$se <- datac$sd / sqrt(datac$N)
ciMult <- qt(conf.interval/2 + .5, datac$N-1)
datac$ci <- datac$se * ciMult
return(datac)
}
When I call this function, it gives sd(standard deviation), se(standard error) and ci(confidence interval), but shows NAfor meanwhat is "vrn1" in my data, and also shows warnings. As far as I understand, this may be a problem in the function summarySE, but I cannot find out where / why.
Can anyone help me solve this problem. or guide me how to write a simple function summarySE?