Re: [問題] 想連續處理多個column by factor
try if this function works!!
yeild <- function(pdt="Product1",month="Jan",volume=year,output_name="Product1_Jan.csv"){
output <- matrix(0,sum(sapply(year,nrow)),10)
for(k in 1:10){
tmpdata <- year[[k]]
output[1:sum(tmpdata$Month==month),k] <- tmpdata[which(tmpdata$Month==month),which(colnames(tmpdata)==pdt)]
}
output <- output[rowSums(output)>0,]
colnames(output) <- c(paste("year0",1:9,sep=""),"year10")
if( is.null(output_name) ){ output_name <- paste(pdt,"_",month,".csv",sep="") }
write.csv(output,file=output_name)
}
yeild()
test <- read.csv("Product1_Jan.csv")
test
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.73.70.8
→
10/28 17:03, , 1F
10/28 17:03, 1F
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):
R_Language 近期熱門文章
PTT數位生活區 即時熱門文章