Hello, Everyone, I am a student an a new learner of R and I am trying to do my homework in R. I have 10 files need to be read and process seperately. I really want to write the codes into something like "macro" to save the lines instead of repeating 10 times of similar work.
The following is part of my codes and I only extracted three lines for each repeating section. data.1 <- read.csv("http://pegasus.cc.ucf.edu/~xsu/CLASS/STA6704/pat1.csv", header = TRUE, sep = ",", quote = "", fill = TRUE); data.2 <- read.csv("http://pegasus.cc.ucf.edu/~xsu/CLASS/STA6704/pat3.csv", header = TRUE, sep = ",", quote = "", fill = TRUE); data.3 <- read.csv("http://pegasus.cc.ucf.edu/~xsu/CLASS/STA6704/pat4.csv", header = TRUE, sep = ",", quote = "", fill = TRUE); baby.1 <- data.frame(cuff=data.1$avg_value, time=seq(1,dim(data.1)[1]), patient=rep(1, dim(data.1)[1])) baby.2 <- data.frame(cuff=data.2$avg_value, time=seq(1,dim(data.2)[1]), patient=rep(3, dim(data.2)[1])) baby.3 <- data.frame(cuff=data.3$avg_value, time=seq(1,dim(data.3)[1]), patient=rep(4, dim(data.3)[1])) I also tried the codes below but it doesn't work. for(n in 1:10){ mm <- data.frame(cuff=paste("data",n, sep=".")$avg_value, time=seq(1,dim(paste("data",n, sep="."))[1]), patient=rep(1,paste("data",n, sep="."))[1])) assign(paste("baby",n,sep="."), mm)} I am looking forward to your help and thanks very much! Xuhong ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.