[R] I get only NA values into my loop - Need to find mean of max CR_Art per Experiment per Mussel

Jeff Rømer jeff.roemer at gmail.com
Sat Oct 1 18:23:18 CEST 2016


Importing datafile "Raadata.csv" 
(Headers: Treatment, Mussel, Experiment, Interval, CR_Art, CR_Rho, CHR‌​_Art, FR_C_Art , CHR_Rho, FR_C_Rho). 
Some fields are empty. Not all treatments have values in all columns. 
read.csv2 is used because of European standards, I have to convert comma to dot.
    Max_CR_FR <- read.csv2(file="Raadata.csv", header=T, sep=";",skipNul=TRUE)
Grouping data by Mussel & Experiment:
    Max_CR_FR$Group= factor(paste(Max_CR_FR$Mussel, Max_CR_FR$Experiment))
Selecting on treatment and de-selecting CR_Art with NA:
    Art=subset(Max_CR_FR, Treatment=="Artemia" & !is.na(Max_CR_FR$CR_Art))
Everything works fine until here at least 
Calculating the mean of maximum values of CR_Art for each group:
    F<-function(Data){
    Exp_max=tapply(Data$CR_Art, Data$Group, max, na.rm=TRUE)
    mean(Exp_max)
    }
Bootstrapping:
    boots=list()
    for(i in 1:1000) boots[[i]]=Art[ sample.int(nrow(Art),replace=TRUE) ,]
    means= lapply( boots, F)
    meanstab = do.call(rbind,means)
Intervals of probability:
    apply(meanstab,2,quantile,probs=c(0.025,0.975),na.rm=TRUE)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 7C05F919DB1B4B869011925C3906D1E6.png
Type: image/png
Size: 15867 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20161001/5ddda036/attachment.png>


More information about the R-help mailing list