Hey,
I have a data set with amounts of yield, 6 different crops, 12 different irrigation scenarios and other variables.
I would like to remove the outliers in the amount of yield for each crop in each irrigation scenario.
My idea was to list grouped over irrigation, loop through the list and combine the resulting df afterwards.
I have tried various ways and none of them work.
The code below works for each irrigation scenario individually but I don't know how to make a loop over all 12 of them.
Thank you for your help!
list = split(data, data$irrigation)
test <- list[[1]]
outliers <-boxplot(list[[1]]$yield ~ list[[1]]$crop, plot=FALSE)$out
test1 <- list[[1]]
test1 <- list[[1]][-which(list[[1]]$yield %in% outliers),]
for (i in 12) {
for (j in nrow(list))
{
test <- list[[i]]
outliers <-boxplot(list[[1]]$yield[j] ~ list[[i]]$crop[j], plot=FALSE)$out
test[i] <- list[[i]]
test[i] <- list[[i]][-which(list[[i]]$yield[j] %in% outliers),]
}
}