[R] quite complicated case(the repeated data arranage~)
Greg Snow
Greg.Snow at imail.org
Thu Jun 5 05:11:53 CEST 2008
For the first question, what do you want to do with all the subsets? There are tools like split, by, lapply, lmList, etc. that make working with all the subsets easy. If you tell us what your final goal is, we may be able to help with a simple solution that does not need the intermediate "tables", at least not explicitly.
For the 2nd question try:
tmp <- paste('x',1:100, sep='')
tmp2 <- lapply(tmp, function(x) get(x)
Xall <- do.call('cbind', tmp2)
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Manli Yan [manliyanrhelp at gmail.com]
Sent: Wednesday, June 04, 2008 6:19 PM
To: r-help at r-project.org
Subject: [R] quite complicated case(the repeated data arranage~)
Hi everyone:
I have been struggling with this repeated data type for whole afternoon,I
sent two emails to server for help,many people kindly responded , hereby
thank you so much,but since I dont want to write to much in email,so I
divide the problem in parts,so far this seem did not work out very well,so
this is my whole problem~
first I have example of data here:
treatment<-c("low","high","high","high","high","low","low","low","low")
age<-c(50,60,50,50,60,50,60,50,60)
y<-c(20,40,30,11,23,24,56,65,60)
id<-c(1,1,3,4,4,6,8,9,9)
table1<-cbind(treatment,id,age,y)
*the actual data are way more than this*,the id is from 1~500,and not in
regular ,some number missing~
all I want to do is
put the cases to variable according the id
for example when id =1
we have
treatment1 age1 y
low 50 20
high 60 40
this will generate a new matrix
for this example I will have 6 new matrix,according to id.
it is reasonable to do this in loop for,but the I met some problem:
1:how to automatically generate the new title such as treatment1 and age1
until treatment 500,age500
2:as you see,id is not strictly from 1 to 500,some time it jump from 15
to19,skip 16,17,18, if I write a loop,it will give me lot NA,certainly I
need a way to avoid this
and one more,say I have 100 vectors like
x1....x100,x1<-c(1,3),x2<-x(2,2),...x100<-(number,number)
I want to combine all this 100 vectors in one new vector say Xall
which is Xall<-cbind(x1,x2,...x100) //this need to type in 100
variables,take alot time
so Xall will be
x1 x2 x3 .....x100
1 2 number
3 2 number
is here any easy way to do this,instead of inputting them one by one?
*and Great Thanks for your time~~*
[[alternative HTML version deleted]]
______________________________________________
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.
More information about the R-help
mailing list