I get only 'NA' values into my loop - Need to find mean of max CR_Art per Experiment per Mussel
0
0
Entering edit mode
7.6 years ago

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)

Confidence interval:

apply(meanstab,2,quantile,probs=c(0.025,0.975),na.rm=TRUE)
R • 1.9k views
ADD COMMENT
1
Entering edit mode

Show head of your original csv data.

ADD REPLY

Login before adding your answer.

Traffic: 2503 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