Re: [R] How to create multi variables

2014-05-14 Thread David Winsemius
On May 13, 2014, at 7:22 PM, yuanzhi wrote: > Thank you for your reply. > > Yes, there is a problem according to you suggestion. > What if the value are not numerical, e.g. I want to use the variable to > store the results of linear regression. > can I use > myvec <- vector( "numeric", 10 ) If

Re: [R] How to create multi variables

2014-05-14 Thread yuanzhi
Yes, it works, thanks for your help. -- View this message in context: http://r.789695.n4.nabble.com/How-to-create-multi-variables-tp4690465p4690572.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list htt

Re: [R] How to create multi variables

2014-05-14 Thread arun
Hi, Try: ls <- vector("list",3) for (i in 1:3)  {    ls[[i]] <- summary(lm(y[,i]~x[,i]))  } names(ls) <- paste0("lm",1:3) A.K. On Wednesday, May 14, 2014 10:45 AM, yuanzhi wrote: Hi, I know all what you said, but it seems that you don't understand my problem. I am sorry about my poor englis

Re: [R] How to create multi variables

2014-05-14 Thread arun
Hi, I guess you can also use ?assign with ?get #For e.g. set.seed(39) mat1 <- matrix(sample(1:10, 10*5, replace=TRUE), ncol=10) vec1 <- paste0("t",1:ncol(mat1)) for(i in 1:ncol(mat1)){  assign(vec1[i], sum(mat1[,i]))  }  t1 #[1] 15  t2 #[1] 28 sapply(vec1,get) # t1  t2  t3  t4  t5  t6  t7  t8  t9

Re: [R] How to create multi variables

2014-05-14 Thread yuanzhi
I am really sorry, I misunderstand your meanings. Your suggestions are useful, and it works! ls<-vector("list",3) for(i in 1:3) { ls[[i]]<-summary(lm(y[,i]~x[,i])) } Thanks for your help very much and sorry for my mistake. -- View this message in context: http://r.789695.n4.nabble.com/How-

Re: [R] How to create multi variables

2014-05-14 Thread yuanzhi
Hi, I know all what you said, but it seems that you don't understand my problem. I am sorry about my poor english level. I know that we can use a list to store complicated objects. e.g. x<-cbind(rnorm(10),rnorm(10),rnorm(10)) y<-cbind(rnorm(10),rnorm(10),rnorm(10)) lm1<-summary(lm(y[,1]~x[,1])) lm2

Re: [R] How to create multi variables

2014-05-13 Thread Jeff Newmiller
Please do the reading I recommended before posting again. My example was numeric because your example was numeric. For more complicated data, a list is a type of vector that can hold such objects, and you would know this if you had read the intro document. ---

Re: [R] How to create multi variables

2014-05-13 Thread yuanzhi
Thank you for your reply. Yes, there is a problem according to you suggestion. What if the value are not numerical, e.g. I want to use the variable to store the results of linear regression. can I use myvec <- vector( "numeric", 10 ) for ( i in 1:10 ) { myvec[ i ] <- summary(lm(y~x)) # y and x a

Re: [R] How to create multi variables

2014-05-13 Thread Jeff Newmiller
What is wrong with myvec <- vector( "numeric", 10 ) for ( i in 1:10 ) { myvec[ i ] <- i } ? If you are using assign, IMHO you are probably doing whatever you are doing wrong. If you want named elements, give the vector names: names( myvec ) <- paste0( "t", 1:10 ) and you can refer to them

[R] How to create multi variables

2014-05-13 Thread Yuanzhi Li
Hi, everyone I want to create a series of variables (e.g. t1, t2..., t10) which could be used in loops. My idea is to use function "assign" for (i in 1:10) { assign(paste("t",i,sep=""), FUN) # allocate the value from FUN to variable ti } But when I create a vector containing the names of