Trying To learn again
2011-Jul-05 11:00 UTC
[R] Executing a function several time, how to save the output
Hi all, I try to exceute a function "myfun" that should use as input "input1.csv" and "input2.csv" . Then I try to save the output dat33 on a csv file (on per each time I execute input1..input 2 and so on). So my problem is how to finally obtain several csv file with "ggt1.csv", "ggt2.csv". The program creates ggt1.csv but BUT when runs "myfun" by second time (It is supossed with input2.csv" it appears: Warning messages: 1: In if (file == "") file <- stdout() else if (is.character(file)) { : the condition has length > 1 and only the first element will be used 2: In file(file, ifelse(append, "a", "w")) : only first element of 'description' argument used 3: In if (file == "") file <- stdout() else if (is.character(file)) { : the condition has length > 1 and only the first element will be used 4: In file(file, ifelse(append, "a", "w")) : only first element of 'description' argument used Do you understand what the message says? files <- paste('input', 1:2, '.csv', sep = '') myfun <- function(d) { dat <- read.csv(d, header = TRUE) dat33<-dat+4 n<-ncol(dat33) m<-nrow(dat33) write.csv(dat33, file =write.csv(dat33, file =paste('ggt', 1:2, '.csv', sep = ' ')) } lout<- lapply(files, myfun) [[alternative HTML version deleted]]
Trying To learn again
2011-Jul-05 15:51 UTC
[R] Executing a function several time, how to save the output
Hi, I find the solution¡¡¡ It was the 1:2 so if I put a loop for i....and replace it works¡¡¡ So Many Thanks¡¡¡ Forget My doubt¡¡ 2011/7/5 Trying To learn again <tryingtolearnagain@gmail.com>> Hi all, > > I try to exceute a function "myfun" that should use as input "input1.csv" > and "input2.csv" . > > Then I try to save the output dat33 on a csv file (on per each time I > execute input1..input 2 and so on). So my problem is how to finally obtain > several csv file with "ggt1.csv", "ggt2.csv". > > The program creates ggt1.csv but > > BUT when runs "myfun" by second time (It is supossed with input2.csv" it > appears: > > > Warning messages: > 1: In if (file == "") file <- stdout() else if (is.character(file)) { : > the condition has length > 1 and only the first element will be used > 2: In file(file, ifelse(append, "a", "w")) : > only first element of 'description' argument used > 3: In if (file == "") file <- stdout() else if (is.character(file)) { : > the condition has length > 1 and only the first element will be used > 4: In file(file, ifelse(append, "a", "w")) : > only first element of 'description' argument used > Do you understand what the message says? > > > > files <- paste('input', 1:2, '.csv', sep = '') > myfun <- function(d) { > dat <- read.csv(d, header = TRUE) > > dat33<-dat+4 > n<-ncol(dat33) > m<-nrow(dat33) > write.csv(dat33, file =write.csv(dat33, file =paste('ggt', 1:2, '.csv', sep > = ' ')) > } > > lout<- lapply(files, myfun) >[[alternative HTML version deleted]]