Hello,
I'm new to Rstudio and I have a problem that I can't solve by looking at the forum :
I would like to make a loop in R, to be able to calculate the yield, according to several factors of my data frame (variety, years, seeding depth...). The loop I created works but the data that comes out of it is not interpretable (long list of data, we don't know what is what).
listyear<- unique(data$year)
print(listyear)
listtype<- unique(data$Type)
print(listtype)
listvariety<- unique(data$VarFH.PH)
print(listvariety
listseed<- unique(data$Appli1.2)
print(listseed)
for (yy in c(1:length(listyear))){
for (xx in c(1:length(listvariety))) {
for (zz in c(1:length(listseed))) {
for(ww in c(1:length(listtype))) {
mean_yeald_type1<-mean(data$yeald [which((data$Type==listtype[ww])&(data$VarFH.PH==listvariety[xx])&(data$Appli1.2==listseed[zz]))], na.rm=TRUE)
print(mean_yeald_type1)
}
}
}
tmp <- fp[which(data$year==listyear[yy]),]
}
Do you have any advice for me?
Thank you in advance for your help.
Louna