hi, I know how to use the "for" loop function like: for(i in 1:ncol(mat)){ mat[i]<-b[i,2] } but, in this case r1<-b[1,1] r2<-b[2,1] r3<-b[3,1] r4<-b[4,1] * * * r3002<-b[3002,1] r3003<-b[3003,1] - must make vectors how should I make a efficient code for that? Is there anything in R like SAS MACRO function? Please help me. -- View this message in context: http://r.789695.n4.nabble.com/macro-function-tp4425446p4425446.html Sent from the R help mailing list archive at Nabble.com.
On Mon, Feb 27, 2012 at 9:56 AM, mrzung <mrzung46 at gmail.com> wrote:> hi, > > I know how to use the "for" loop function like: > > for(i in 1:ncol(mat)){ > mat[i]<-b[i,2] > } > > but, in this case > > r1<-b[1,1] > r2<-b[2,1] > r3<-b[3,1] > r4<-b[4,1] > > * > * > * > > r3002<-b[3002,1] > r3003<-b[3003,1] > > - must make vectors > > how should I make a efficient code for that?You shouldn't. There is no reason to do this.> > Is there anything in R like SAS MACRO function?No! -- Thank goodness! R is a programming language to begin with. Have you read "An Intro to R?' If not, why not? There are numerous resources available on CRAN to help you. Use them.> > Please help me. >Please first make an effort to help yourself. -- Bert> > > -- > View this message in context: http://r.789695.n4.nabble.com/macro-function-tp4425446p4425446.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
hi, I know how to use the "for" loop function like: for(i in 1:ncol(mat)){ mat[i]<-b[i,2] } but, in this case r1<-b[1,1] r2<-b[2,1] r3<-b[3,1] r4<-b[4,1] * * * r3002<-b[3002,1] r3003<-b[3003,1] - must make vectors how should I make a efficient code for that? Is there anything in R like SAS MACRO function? -- View this message in context: http://r.789695.n4.nabble.com/macro-function-tp4427385p4427385.html Sent from the R help mailing list archive at Nabble.com.
Hi Your mail is quite messy. what is ***? How your data are structured? str(your.data) Please submit part of your data by dput(your.data) and show what the output shall be. Regards Petr> > Actually, what I really want to do is that, > > > <<"annual productivity data(2011)">> > > firts date 2011-01-01 2011-01-02> 2011-01-03 2011-01-04 2011-01-05 * * > * > A 2011-02-03 0 > 0 0 > 0 0 * * * > B 2011-01-02 0 > 10 11 > 12 > 13 * * * > C 2011-04-02 0 > 0 > 11 12 > 13 > * * * > D 2011-02-02 0 > 0 0 > 0 0 * * * > E 2011-11-02 0 > 0 0 > 0 0 * * * > * > * > * > > I have this "annual productivity data(2011)" and I need to convert thisas> "D-Day data". That is to say, I need this form. > > firts date D-DAY D+1 > D+2 D+3 D+4 > * * * > A 2011-02-03 0 > 0 > 0 0 > 0 * * * > B 2011-01-02 0 > 10 > 11 12 > 13 > * * * > C 2011-04-02 0 > 0 > 11 12 > 13 > * * * > D 2011-02-02 0 > 0 > 0 0 > 0 * * * > E 2011-11-02 0 > 0 0 > 0 0 * * * > > * > * > * > > D-day is the "first date" and each cells are day-productivity of theday.> > how can I make a code for that? > > -- > View this message in context: http://r.789695.n4.nabble.com/macro- > function-tp4427385p4428131.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
I really appreciate to your attention. I want to change the data form "A" into "B" http://r.789695.n4.nabble.com/file/n4428807/1.png http://r.789695.n4.nabble.com/file/n4428807/2.png In fact, there are 1095 column in data "A". Specifically, variable "publish_day" is when some book in the same row is published and "D-1", "D-2" means the term after the "publish day". Of course, the cells in data mean productivity in the day. What can be effecient way to do it? -- View this message in context: http://r.789695.n4.nabble.com/macro-function-tp4427385p4428807.html Sent from the R help mailing list archive at Nabble.com.
On Feb 28, 2012, at 12:10 PM, mrzung wrote:> I really appreciate to your attention. > > I want to change the data form "A" into "B" > > > http://r.789695.n4.nabble.com/file/n4428807/1.png > > > http://r.789695.n4.nabble.com/file/n4428807/2.pngPlease use text copied versions of dput(a) and dput(b) rather than posting bitmapped images of your screen.> > > In fact, there are 1095 column in data "A". > Specifically, variable "publish_day" is when some book in the same > row is > published and > "D-1", "D-2" means the term after the "publish day". > Of course, the cells in data mean productivity in the day. > > What can be effecient way to do it?Specify what you want tot do in English. Asking how to create 1000 separate variable is almost certainly to be the wrong way to go. If you wanted a list with names like that we can probably help. -- David Winsemius, MD Heritage Laboratories West Hartford, CT