Hey Sky
2010-Aug-04 00:29 UTC
[R] does R have a command the same with Stata's loop command: ` '
hey, Rers in Stata therer is a loop command ` ' which could do the following: forvalue i=1/10 { ?gen?x`i'=expression } this will generate variable: x1,x2,,,,,x10. so, does R have a corresponding one to this? And one more very basic question: after I open a file and modify it, such as generate some new variables and change some old ones, how to use the changed dataset in analysis,?except the method?save?and reload it? I have tried but did not get the right thing done: mydata<-read(flie=".....") ........ detach() attach(names of my data set) any answer are appreciated. Nan from Montreal
jim holtman
2010-Aug-04 00:39 UTC
[R] does R have a command the same with Stata's loop command: ` '
?paste ?assign On Tue, Aug 3, 2010 at 8:29 PM, Hey Sky <heyskywalker at yahoo.com> wrote:> hey, Rers > > in Stata therer is a loop command ` ' which could do the following: > > forvalue i=1/10 { > ?gen?x`i'=expression > } > > this will generate variable: x1,x2,,,,,x10. so, does R have a corresponding one > to this? > > > And one more very basic question: after I open a file and modify it, such as > generate some new variables and change some old ones, how to use the changed > dataset in analysis,?except the method?save?and reload it? > > > I have tried but did not get the right thing done: > mydata<-read(flie=".....") > ........ > detach() > attach(names of my data set) > > > any answer are appreciated. > > Nan > from Montreal > > > > ______________________________________________ > R-help at r-project.org 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Greg Snow
2010-Aug-04 17:28 UTC
[R] does R have a command the same with Stata's loop command: ` '
Do ?'for' to learn about for loops. Look at FAQ 7.21 for the other part of the question (the most important part of the answer is the end where it tells you to use lists instead like Patrick suggests). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Hey Sky > Sent: Tuesday, August 03, 2010 6:30 PM > To: R > Subject: [R] does R have a command the same with Stata's loop command: > ` ' > > hey, Rers > > in Stata therer is a loop command ` ' which could do the following: > > forvalue i=1/10 { > ?gen?x`i'=expression > } > > this will generate variable: x1,x2,,,,,x10. so, does R have a > corresponding one > to this? > > > And one more very basic question: after I open a file and modify it, > such as > generate some new variables and change some old ones, how to use the > changed > dataset in analysis,?except the method?save?and reload it? > > > I have tried but did not get the right thing done: > mydata<-read(flie=".....") > ........ > detach() > attach(names of my data set) > > > any answer are appreciated. > > Nan > from Montreal > > > > ______________________________________________ > R-help at r-project.org 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.