I expected to get an output of cleaned data in 4 sheets and each with 9 columns. Original data looks like this:
but only output the first column in the first sheet:
my codes are as below:
library(readxl)
library(xlsx)
library(triangle)
library(dplyr)
library(Matrix)
library(qpcR)
library(ggplot2)
sheetlist <- as.list(1,2,3,4)
columnlist <- as.list(1,2,3,4,11,12,13,14,15)
output <- data.frame(matrix(nrow = 800))
for (i in sheetlist){
page <- read.xlsx(
"C:\\Users\\WangShiqin\\Desktop\\data all required.xlsx",
i, header = TRUE)
for (j in columnlist){
variable <- page %>% dplyr::select(all_of(j))
outliers <- boxplot(variable, plot = FALSE)$out
cleaned <- variable[-c(which(variable[,1] %in% outliers)), ]
output <- qpcR:::cbind.na(output, cleaned)
}
if (i<2){
write.xlsx(output,
"C:\\Users\\WangShiqin\\desktop\\cleaned.xlsx")
}
else{
write.xlsx(output,
"C:\\Users\\WangShiqin\\desktop\\cleaned.xlsx",
sheetindex = i, append = TRUE)
}
}
but it only generates the cleaned result of the first column in first sheet