HI Usha, For your first question (saw ur posting in Nabble). I subset the data on the reshaped long format data which has time variable. Please check my previous email. BP.stacknormal<-subset(BP.stack3,Obese==0 & Overweight==0) ^^^^^^^ The variable "Categ" was created to identify the levels "Normal", "Obese" in the reshaped data. You should also create "Overweight" just like I created the others and rbind the three subsets. I would do mixed effects model with all the three "Normal", "Obese", "Overweight" in the same model as you wanted random effects in the model. Regarding the mixed effects model, it would be good to post the question in R mixed models (r-sig-mixed-mod...@r-project.org) mailing group as it specifically deals with this kind of problems. I can't say whether nlme or lme4 is better in this case. You could fit the model with several other variables and select the best model based on different criteria. Happy New Year! A.K.
________________________________ From: Usha Gurunathan <usha.nat...@gmail.com> To: arun <smartpink...@yahoo.com> Sent: Sunday, December 30, 2012 7:15 AM Subject: Re: [R] help with reshaping wide to long format Hi Arun I have attached the data set . The research question(one of them) I am trying to figure a way out is: Do children who are obese or overweight at age 14 experience different change in blood pressure by 21 years, compared to those with normal weight at age 14? Also a way to deal with huge no. of missing values?. Sorry, the above is probably not to do with R programming. No obligations, you dont have to answer them if you are not keen to. Thanks, Usha On Sun, Dec 30, 2012 at 1:22 AM, arun <smartpink...@yahoo.com> wrote: HI Usha, >How big is the original data? YOu can check with (dim(Yourdata)). If you >could email the dataset, I will look into it. Also, check whether the format >of the data is correct for all the rows. Sometimes, spaces could alter the >columns and create this kind of problems. > >With regards to the comparison, I don't know the range of normal weight for 21 >yrs old. I would assume it depends upon height, sex, BMI etc. In the subset >data you sent to me, there were no columns with height, sex, or BMI. If it >had, then you may use ?sample() with ranges of weight for each of the >combinations of categories (height, sex, BMI). In this case, with very >options, I am not sure about the right way to proceed. >Arun > > > > > > > > > >________________________________ >From: Usha Gurunathan <usha.nat...@gmail.com> >To: arun <smartpink...@yahoo.com> >Sent: Saturday, December 29, 2012 7:36 AM > >Subject: Re: [R] help with reshaping wide to long format > > >Hi > >I am able to get the output with the subset showing the two time periods .. >With my master data, I cannot see the time=2 ( same code , just replaced the >data frame.). May be thats the max. it could print. Any way, I cross checked >few random numbers in the wide and long format ,they tally. Many thanks for >your time and patience. > >With the same data, if I have to compare the change in blood pressure by 21 >yrs between obese/overweight 14 versus normal weight at 14 (there is no normal >weight group in the data), is there any way that I can produce a normal weight >group? > >Any help would be appreciated. > >Usha > > > > >On Fri, Dec 28, 2012 at 11:23 PM, arun <smartpink...@yahoo.com> wrote: > >Hi, >>DId you tried "copy and paste" the code in my reply? If not, please do. >> >>In your previous replies, you forgot to close the bracket(")") or adding "#" >>in between the codes. Please check your codes. >> >>It would be also helpful to read the posting guide >>(http://www.r-project.org/posting-guide.html) and "An introduction to R" (the >>link will be in the posting guide). >> >>A.K. >> >> >> >> >> >>----- Original Message ----- >>From: usha2013 <usha.nat...@gmail.com> >>To: r-help@r-project.org >>Cc: >>Sent: Friday, December 28, 2012 2:02 AM >>Subject: Re: [R] help with reshaping wide to long format >> >>Hi, Sorry, but how did you bring it out? >> >>Thanks >> >>On Fri, Dec 28, 2012 at 8:48 AM, arun kirshna [via R] < >>ml-node+s789695n4654093...@n4.nabble.com> wrote: >> >>> Hi, >>> bp.sub<- structure(list(CODEA = c(1L, 3L, 4L, 7L, 8L, 9L, 10L, 11L, 12L, >>> 13L, 14L, 16L, 17L), C45 = c(NA, 2L, 2L, 2L, 2L, 1L, NA, 1L, >>> 1L, 2L, 1L, 2L, 1L), ragek = c(3L, 3L, 3L, 4L, 4L, 3L, 3L, 3L, >>> 3L, 3L, 3L, 3L, 3L), ra80 = c(4L, 3L, 6L, 6L, 4L, 6L, 3L, 4L, >>> 4L, 4L, 4L, 4L, 4L), ra98 = c(1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, >>> 2L, 2L, 2L, 3L, 1L), CBCLAggressionAt1410 = c(NA, 0L, NA, 0L, >>> 0L, 0L, NA, 0L, NA, NA, 0L, 0L, NA), CBCLInternalisingAt1410 = c(NA, >>> 0L, NA, 0L, 0L, 0L, NA, 0L, NA, NA, 0L, 0L, NA), Obese14 = c(NA, >>> 0L, NA, 0L, 0L, 0L, NA, NA, NA, NA, 0L, 0L, NA), Obese21 = c(NA, >>> 0L, NA, 1L, 0L, 0L, NA, 0L, NA, NA, 0L, 0L, NA), Overweight14 = c(NA, >>> 0L, NA, 0L, 0L, 0L, NA, NA, NA, NA, 0L, 0L, NA), Overweight21 = c(NA, >>> 1L, NA, 1L, 0L, 0L, NA, 0L, NA, NA, 1L, 0L, NA), hibp14 = c(NA, >>> 0L, NA, 0L, 0L, 0L, NA, NA, NA, NA, 1L, 1L, NA), hibp21 = c(NA, >>> 0L, NA, 0L, 0L, 0L, NA, 0L, NA, NA, 1L, NA, NA)), .Names = c("CODEA", >>> "C45", "ragek", "ra80", "ra98", "CBCLAggressionAt1410", >>> "CBCLInternalisingAt1410", >>> "Obese14", "Obese21", "Overweight14", "Overweight21", "hibp14", >>> "hibp21"), row.names = c(NA, 13L), class = "data.frame") >>> >>> BP.stack1<- reshape(bp.sub,sep="",timevar= >>> "time",direction="long",varying=list(names(bp.sub[8:9]),names(bp.sub[10:11]),names(bp.sub[12:13])),v.names=c("Obese","Overweight","HiBP"),idvar="CODEA") >>> >>> BP.stack1$time <- recode(BP.stack1$time,("1=14;2=21")) >>> BP.stack1 >>> # CODEA C45 ragek ra80 ra98 CBCLAggressionAt1410 >>> CBCLInternalisingAt1410 >>> #1.1 1 NA 3 4 1 NA >>> NA >>> #3.1 3 2 3 3 1 0 >>> 0 >>> #4.1 4 2 3 6 1 NA >>> NA >>> #7.1 7 2 4 6 1 0 >>> 0 >>> #8.1 8 2 4 4 1 0 >>> 0 >>> #9.1 9 1 3 6 2 0 >>> 0 >>> #10.1 10 NA 3 3 1 NA >>> NA >>> #11.1 11 1 3 4 1 0 >>> 0 >>> #12.1 12 1 3 4 2 NA >>> NA >>> #13.1 13 2 3 4 2 NA >>> NA >>> #14.1 14 1 3 4 2 0 >>> 0 >>> #16.1 16 2 3 4 3 0 >>> 0 >>> #17.1 17 1 3 4 1 NA >>> NA >>> #1.2 1 NA 3 4 1 NA >>> NA >>> #3.2 3 2 3 3 1 0 >>> 0 >>> #4.2 4 2 3 6 1 NA >>> NA >>> #7.2 7 2 4 6 1 0 >>> 0 >>> #8.2 8 2 4 4 1 0 >>> 0 >>> #9.2 9 1 3 6 2 0 >>> 0 >>> #10.2 10 NA 3 3 1 NA >>> NA >>> #11.2 11 1 3 4 1 0 >>> 0 >>> #12.2 12 1 3 4 2 NA >>> NA >>> #13.2 13 2 3 4 2 NA >>> NA >>> #14.2 14 1 3 4 2 0 >>> 0 >>> #16.2 16 2 3 4 3 0 >>> 0 >>> #17.2 17 1 3 4 1 NA >>> NA >>> # time Obese Overweight HiBP >>> #1.1 14 NA NA NA >>> #3.1 14 0 0 0 >>> #4.1 14 NA NA NA >>> #7.1 14 0 0 0 >>> #8.1 14 0 0 0 >>> #9.1 14 0 0 0 >>> #10.1 14 NA NA NA >>> #11.1 14 NA NA NA >>> #2.1 14 NA NA NA >>> #13.1 14 NA NA NA >>> #14.1 14 0 0 1 >>> #16.1 14 0 0 1 >>> #17.1 14 NA NA NA >>> #1.2 21 NA NA NA >>> #3.2 21 0 1 0 >>> #4.2 21 NA NA NA >>> #7.2 21 1 1 0 >>> #8.2 21 0 0 0 >>> #9.2 21 0 0 0 >>> #10.2 21 NA NA NA >>> #11.2 21 0 0 0 >>> #12.2 21 NA NA NA >>> #13.2 21 NA NA NA >>> #14.2 21 0 1 1 >>> #16.2 21 0 0 NA >>> #17.2 21 NA NA NA >>> names(bp.sub)[grep("\\d+",names(bp.sub))]<-gsub("(\\D+)(\\d+)","\\1_\\2",names(bp.sub)[grep("\\d+",names(bp.sub))]) >>> >>> BP.stack2<-reshape(bp.sub,dir="long",varying=8:13,sep="_") >>> Bp.stack2 >>> CODEA C_45 ragek ra_80 ra_98 CBCLAggressionAt_1410 >>> 1.14 1 NA 3 4 1 NA >>> 2.14 3 2 3 3 1 0 >>> 3.14 4 2 3 6 1 NA >>> 4.14 7 2 4 6 1 0 >>> 5.14 8 2 4 4 1 0 >>> 6.14 9 1 3 6 2 0 >>> 7.14 10 NA 3 3 1 NA >>> 8.14 11 1 3 4 1 0 >>> 9.14 12 1 3 4 2 NA >>> 10.14 13 2 3 4 2 NA >>> 11.14 14 1 3 4 2 0 >>> 12.14 16 2 3 4 3 0 >>> 13.14 17 1 3 4 1 NA >>> 1.21 1 NA 3 4 1 NA >>> 2.21 3 2 3 3 1 0 >>> 3.21 4 2 3 6 1 NA >>> 4.21 7 2 4 6 1 0 >>> 5.21 8 2 4 4 1 0 >>> 6.21 9 1 3 6 2 0 >>> 7.21 10 NA 3 3 1 NA >>> 8.21 11 1 3 4 1 0 >>> 9.21 12 1 3 4 2 NA >>> 10.21 13 2 3 4 2 NA >>> 11.21 14 1 3 4 2 0 >>> 12.21 16 2 3 4 3 0 >>> 13.21 17 1 3 4 1 NA >>> CBCLInternalisingAt_1410 time Obese Overweight hibp id >>> 1.14 NA 14 NA NA NA 1 >>> 2.14 0 14 0 0 0 2 >>> 3.14 NA 14 NA NA NA 3 >>> 4.14 0 14 0 0 0 4 >>> 5.14 0 14 0 0 0 5 >>> 6.14 0 14 0 0 0 6 >>> 7.14 NA 14 NA NA NA 7 >>> 8.14 0 14 NA NA NA 8 >>> 9.14 NA 14 NA NA NA 9 >>> 10.14 NA 14 NA NA NA 10 >>> 11.14 0 14 0 0 1 11 >>> 12.14 0 14 0 0 1 12 >>> 13.14 NA 14 NA NA NA 13 >>> 1.21 NA 21 NA NA NA 1 >>> 2.21 0 21 0 1 0 2 >>> 3.21 NA 21 NA NA NA 3 >>> 4.21 0 21 1 1 0 4 >>> 5.21 0 21 0 0 0 5 >>> 6.21 0 21 0 0 0 6 >>> 7.21 NA 21 NA NA NA 7 >>> 8.21 0 21 0 0 0 8 >>> 9.21 NA 21 NA NA NA 9 >>> 10.21 NA 21 NA NA NA 10 >>> 11.21 0 21 0 1 1 11 >>> 12.21 0 21 0 0 NA 12 >>> 13.21 NA 21 NA NA NA 13 >>> A.K. >>> >>> >>> >>> >>> >>> ------------------------------ >> >>> If you reply to this email, your message will be added to the discussion >>> below: >>> >>> http://r.789695.n4.nabble.com/help-with-reshaping-wide-to-long-format-tp4653922p4654093.html >>> To unsubscribe from help with reshaping wide to long format, click >>>here<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4653922&code=dXNoYS5uYXRoYW5AZ21haWwuY29tfDQ2NTM5MjJ8MjAyMjE1NDI0> >>> . >>> NAML<http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >>> >> >> >> >> >>-- >>View this message in context: >>http://r.789695.n4.nabble.com/help-with-reshaping-wide-to-long-format-tp4653922p4654122.html >>Sent from the R help mailing list archive at Nabble.com. >> [[alternative HTML version deleted]] >> >>______________________________________________ >>R-help@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. >> >> > ______________________________________________ R-help@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.