So in fact : I have a data wich colnames are : "id","VEMS5A","VEMS6A","VEMS7A","VEMS8A","VEMS9A","VEMS10A","VEMS11A","VEMS12A","VEMS13A","VEMS14A","VEMS15A","VEMS16A","VEMS17A","VEMS18A","cohort") With "VEMS5A" is the value when the subject (id) was 5 year old,... "VEMS18A" is the value when the subject(id) was 18 year old I want to make a new data wich colnames will be : "id","age", and "VEMS" Where "age" will be the age when the value in "VEMS" was measured for the suject "id"... So I need to copy all the values of the columns "VEMS5A",... "VEMS18A" in "VEMS" and in "id" the "id" corresponding and in "age" the values between 5 and 18 corresponding to the age of the subject when the mesure was done. And this only when the value in "cohort" was 1. -----Message d'origine----- De : F Z [mailto:gerifalte28 at hotmail.com] Envoy? : jeudi 3 f?vrier 2005 19:38 ? : combe at b3e.jussieu.fr; R-help at stat.math.ethz.ch Objet : RE: [R] he^lp on "stack" function In the future please be a little more specific with your questions. i.e. give us an example of your data the way it looks now and the way you want it to look. I think what you want is something like: time<-seq(as.Date("2005/1/1"), as.Date("2005/1/10"), "days") age<-round(runif(10,30,50)) measure<-rnorm(10) mydat<-data.frame(time=time,age=age,measure=measure) #creates a data frame with your 3 #variables time age measure 1 2005-01-01 48 -1.2873181 2 2005-01-02 50 0.5776001 3 2005-01-03 44 0.1892008 4 2005-01-04 38 0.4981651 5 2005-01-05 49 -1.7591745 6 2005-01-06 37 -0.8898464 7 2005-01-07 30 0.7528217 8 2005-01-08 46 -1.2421763 9 2005-01-09 39 -0.9333667 10 2005-01-10 32 1.2086509 #suppose you only want patients older than 40 Older40<-mydat[age>=40,c(1,3)] time measure 1 2005-01-01 -1.2873181 2 2005-01-02 0.5776001 3 2005-01-03 0.1892008 5 2005-01-05 -1.7591745 8 2005-01-08 -1.2421763 Is this what you wanted to do? Francisco>From: "" <combe at b3e.jussieu.fr> >To: "" <R-help at stat.math.ethz.ch> >Subject: [R] he^lp on "stack" function >Date: Thu, 3 Feb 2005 18:10:24 +0100 > > > > >Excuse me. >I don't understant how to use the function "stack". >I'm not sure to know the good syntax. > >I've got a data witch column names are the time when the mesures was >done >and >an >other who indicates the age of the subjetcs. >I would like to do a new matrix with patients older than a value and the >new >matrix will contain in the first column the time of the mesures and in the >second th evalue of the mesure. > >Could you help me please ? > >______________________________________________ >R-help at 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
Check out ?reshape . <combe <at> b3e.jussieu.fr> writes: : : So in fact : : : I have a data wich colnames are : : "id","VEMS5A","VEMS6A","VEMS7A","VEMS8A","VEMS9A","VEMS10A","VEMS11A","VEMS12 A","VEMS13A","VEMS14A","VEMS15A","VEMS16A","VEMS17A","VEMS18A","cohort") : : With "VEMS5A" is the value when the subject (id) was 5 year old,... "VEMS18A" is : the value when the subject(id) was 18 year old : : I want to make a new data wich colnames will be : "id","age", and "VEMS" : Where "age" will be the age when the value in "VEMS" was measured for the suject : "id"... : : So I need to copy all the values of the columns "VEMS5A",... "VEMS18A" in "VEMS" : and in "id" the "id" corresponding and in "age" the values between 5 and 18 : corresponding to the age of the subject when the mesure was done. And this only : when the value in "cohort" was 1. : : -----Message d'origine----- : De : F Z [mailto:gerifalte28 <at> hotmail.com] : Envoyé : jeudi 3 février 2005 19:38 : à : combe <at> b3e.jussieu.fr; R-help <at> stat.math.ethz.ch : Objet : RE: [R] he^lp on "stack" function : : In the future please be a little more specific with your questions. i.e. : give us an example of your data the way it looks now and the way you want : it to look. : : I think what you want is something like: : : time<-seq(as.Date("2005/1/1"), as.Date("2005/1/10"), "days") : age<-round(runif(10,30,50)) : measure<-rnorm(10) : mydat<-data.frame(time=time,age=age,measure=measure) #creates a data frame : with your 3 #variables : : time age measure : 1 2005-01-01 48 -1.2873181 : 2 2005-01-02 50 0.5776001 : 3 2005-01-03 44 0.1892008 : 4 2005-01-04 38 0.4981651 : 5 2005-01-05 49 -1.7591745 : 6 2005-01-06 37 -0.8898464 : 7 2005-01-07 30 0.7528217 : 8 2005-01-08 46 -1.2421763 : 9 2005-01-09 39 -0.9333667 : 10 2005-01-10 32 1.2086509 : : #suppose you only want patients older than 40 Older40<-mydat[age>=40,c(1,3)] : time measure : 1 2005-01-01 -1.2873181 : 2 2005-01-02 0.5776001 : 3 2005-01-03 0.1892008 : 5 2005-01-05 -1.7591745 : 8 2005-01-08 -1.2421763 : : Is this what you wanted to do? : : Francisco : : >From: "" <combe <at> b3e.jussieu.fr> : >To: "" <R-help <at> stat.math.ethz.ch> : >Subject: [R] he^lp on "stack" function : >Date: Thu, 3 Feb 2005 18:10:24 +0100 : > : > : > : > : >Excuse me. : >I don't understant how to use the function "stack". : >I'm not sure to know the good syntax. : > : >I've got a data witch column names are the time when the mesures was : >done : >and : >an : >other who indicates the age of the subjetcs. : >I would like to do a new matrix with patients older than a value and the : >new : >matrix will contain in the first column the time of the mesures and in the : >second th evalue of the mesure. : > : >Could you help me please ? : > : >______________________________________________ : >R-help <at> 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 : : ______________________________________________ : R-help <at> 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 : :