hey Leon
I think you method works best for me and your example surely works now my followup question.
data is a dataframe
so I extended your idea to this
where I get this error
Error in loc[[locis]] <- zones[[zonename]] %>% filter(location == locis) :
invalid subscript type 'list'
on this line:
loc[[locis]]<-zones[[zonename]] %>% filter(location==locis)
for some reason loc which is a list of dataframes is causing the issue...any ideas?
zones = list()
loc = list()
zonesReport = list()
locReport = list()
zonesAnova = list()
locAnova = list()
x<-data %>% filter(zone==1)
ulocx<-unique(x[c("location")])
numulocx<-nrow(unique(x[c("location")]))
loc[j]<-data %>% filter(location==ulocx[1])
ulocx[2,1]
for(i in 1:numzone)
{
zonename<-paste("Zone",i, sep = "")
zones[[zonename]]<-data %>% filter(zone==i)
numlocalhere<-nrow(unique(zones[[zonename]][c("location")]))
localhere<-unique(zones[[zonename]][c("location")])
print(zonename)
print(i)
j=0
for (z in 1:numlocalhere)
{
j=j+1
locis=ulocx[z,1]
locname<-paste("Zone",i,"-",locis, sep = "")
loc[[locis]]<-zones[[zonename]] %>% filter(location==locis)
locReport[[locis]] <- loc[[locis]] %>%
group_by(name) %>%
summarise(AVG = mean(yield_kgha , na.rm = TRUE),n=n(),StdDev=sd(yield_kgha , na.rm = TRUE),cvpct=((sd(yield_kgha , na.rm = TRUE)/mean(yield_kgha , na.rm = TRUE))*100))
locAnova[[locis]] <- loc[[locis]] %>% group_by(zone,location,name)
modeldw1<-aov(yield_kgha~name+bloc,data=locAnova[z])
order<-loc[z] %>% group_by(name) %>% summarize(n=n())
max(order$n)
dfx<-tail(summary(modeldw1)[[1]]$`Df`, n=1)
msx<-tail(summary(modeldw1)[[1]]$`Mean Sq`, n=1)
meanis=mean(loc[z]$yield_kgha)
stddevis=sd(loc[z]$yield_kgha)
cvpctis=(stddevis/meanis)*100
lsdis<-abs(qt(0.05/2,dfx*1))*sqrt(msx*2/(33))
write.csv(locReport[[locis]],paste(csvdir,"\\",locname,".csv", sep = ""), row.names = TRUE)
write.table(paste("lsd at 5%", lsdis), paste(csvdir,"\\data",i,".csv", sep = ""), col.names = !file.exists(filename), append = T)
write.table(paste("CV%:", cvpctis), paste(csvdir,"\\data",i,".csv", sep = ""), col.names = !file.exists(filename), append = T)
#write.table(paste("# Locations:", numlocalhere), paste(csvdir,"\\data",i,".csv", sep = ""), col.names = !file.exists(filename), append = T)
}
}