Re: [問題] 想連續處理多個column by factor

看板R_Language作者 (可笑的自以為...)時間11年前 (2013/10/24 19:16), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串4/4 (看更多)
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
thanks
10/28 17:03, 1F
文章代碼(AID): #1IQG61SD (R_Language)
文章代碼(AID): #1IQG61SD (R_Language)