Re: [R] how to write a loop to repetitive jobs

2018-04-18 Thread jim holtman
Try this: result <- lapply(71:75, function(x){ # use 'paste0' to add the number to the file name input <- read.csv(paste0("C:/Awork/geneAssociation/removed8samples/neuhausen", x, "/seg.pr3.csv") , head=TRUE )

Re: [R] how to write a loop to repetitive jobs

2018-04-17 Thread K. Elo
Hi! An alternative with 'assign': for ( i in 71:75) {   setwd(paste("C:/Awork/geneAssociation/removed8samples/neuhausen", i, sep=""))   temp.df<-read.csv("seg.pr3.csv", head=T)   temp.df$id<-paste0("sn",i,sep="")   assign(paste0("seg",i,sep=""),temp.df) } rm(temp.df,i)    # Clean up HTH, Kimmo

Re: [R] how to write a loop to repetitive jobs

2018-04-17 Thread Albrecht Kauffmann
Hello Ding, try this: seg <- list() for ( d in 71:75) { s <- paste0("seg",d) sn <- paste0("sn",d) Dir<-paste("C:/Awork/geneAssociation/removed8samples/neuhausen", i, sep="") setwd(Dir) seg[[s]] <- read.csv("seg.pr3.csv", head=T) seg[[s]]$id <- sn } Greetings, Albrecht --

Re: [R] how to write a loop to repetitive jobs

2018-04-16 Thread Ding, Yuan Chun
Hi Rui, Thank you very much!! It worked very well, I am looking into how to use lapply and do.call. Ding -Original Message- From: Rui Barradas [mailto:ruipbarra...@sapo.pt] Sent: Monday, April 16, 2018 2:16 PM To: Ding, Yuan Chun; r-help@r-project.org Subject: Re: [R] how to write a

Re: [R] how to write a loop to repetitive jobs

2018-04-16 Thread Rui Barradas
Hello, The following might do it. Without data it's untested. wd <- function(i){ paste0("C:/Awork/geneAssociation/removed8samples/neuhausen7", i, "/seg.pr3.csv") } seg <- lapply(1:5, function(i) { DF <-read.csv(wd(i)) DF$id <- paste0("sn7", i) DF }) seg <- do.call(rbind,