Hello, I try out to create a new form from the below data.frame. I would like to have this form: V3 Santiago Ourense Vigo Ferrol 2013-07-04 2013-07-04 07:01:04 ...................................... How can i get this?> str(sunrise)'data.frame': 24 obs. of 3 variables: $ day_frac: Factor w/ 4 levels "Ferrol","Ourense",..: 3 2 4 1 3 2 4 1 3 2 ... $ time : POSIXct, format: "2013-07-04 07:01:04" ... $ V3 : Factor w/ 6 levels "2013-07-04","2013-07-05",..: 1 1 1 1 2 2 2 2 3 3 ...> sunriseday_frac time V3 1 Santiago 2013-07-04 07:01:04 2013-07-04 2 Ourense 2013-07-04 07:00:05 2013-07-04 3 Vigo 2013-07-04 07:04:06 2013-07-04 4 Ferrol 2013-07-04 06:57:38 2013-07-04 5 Santiago 2013-07-05 07:01:41 2013-07-05 6 Ourense 2013-07-05 07:00:41 2013-07-05 7 Vigo 2013-07-05 07:04:42 2013-07-05 8 Ferrol 2013-07-05 06:58:16 2013-07-05 9 Santiago 2013-07-06 07:02:20 2013-07-06 10 Ourense 2013-07-06 07:01:19 2013-07-06 11 Vigo 2013-07-06 07:05:20 2013-07-06 12 Ferrol 2013-07-06 06:58:56 2013-07-06 Thanks, Regards [[alternative HTML version deleted]]
https://github.com/hadley/devtools/wiki/Reproducibility http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example John Kane Kingston ON Canada> -----Original Message----- > From: dominic.roye at gmail.com > Sent: Tue, 30 Jul 2013 15:41:46 +0200 > To: r-help at r-project.org > Subject: [R] Reshape > > Hello, > > I try out to create a new form from the below data.frame. > > I would like to have this form: > > V3 Santiago Ourense Vigo Ferrol > 2013-07-04 2013-07-04 07:01:04 ...................................... > > How can i get this? > >> str(sunrise) > 'data.frame': 24 obs. of 3 variables: > $ day_frac: Factor w/ 4 levels "Ferrol","Ourense",..: 3 2 4 1 3 2 4 1 3 > 2 > ... > $ time : POSIXct, format: "2013-07-04 07:01:04" ... > $ V3 : Factor w/ 6 levels "2013-07-04","2013-07-05",..: 1 1 1 1 2 2 > 2 > 2 3 3 ... > >> sunrise > day_frac time V3 > 1 Santiago 2013-07-04 07:01:04 2013-07-04 > 2 Ourense 2013-07-04 07:00:05 2013-07-04 > 3 Vigo 2013-07-04 07:04:06 2013-07-04 > 4 Ferrol 2013-07-04 06:57:38 2013-07-04 > 5 Santiago 2013-07-05 07:01:41 2013-07-05 > 6 Ourense 2013-07-05 07:00:41 2013-07-05 > 7 Vigo 2013-07-05 07:04:42 2013-07-05 > 8 Ferrol 2013-07-05 06:58:16 2013-07-05 > 9 Santiago 2013-07-06 07:02:20 2013-07-06 > 10 Ourense 2013-07-06 07:01:19 2013-07-06 > 11 Vigo 2013-07-06 07:05:20 2013-07-06 > 12 Ferrol 2013-07-06 06:58:56 2013-07-06 > > > > > Thanks, > > Regards > > [[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.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
Hi, Please use ?dput() for the example data sunrise<- structure(list(day_frac = c("Santiago", "Ourense", "Vigo", "Ferrol", "Santiago", "Ourense", "Vigo", "Ferrol", "Santiago", "Ourense", "Vigo", "Ferrol"), time = structure(c(1372935664, 1372935605, 1372935846, 1372935458, 1373022101, 1373022041, 1373022282, 1373021896, 1373108540, 1373108479, 1373108720, 1373108336), class = c("POSIXct", "POSIXt"), tzone = ""), V3 = c("2013-07-04", "2013-07-04", "2013-07-04", "2013-07-04", "2013-07-05", "2013-07-05", "2013-07-05", "2013-07-05", "2013-07-06", "2013-07-06", "2013-07-06", "2013-07-06")), .Names = c("day_frac", "time", "V3"), row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"), class = "data.frame") library(reshape2) res<-dcast(sunrise,V3~day_frac,value.var="time") res ?# ??????? V3????????????? Ferrol???????????? Ourense??????????? Santiago #1 2013-07-04 2013-07-04 06:57:38 2013-07-04 07:00:05 2013-07-04 07:01:04 #2 2013-07-05 2013-07-05 06:58:16 2013-07-05 07:00:41 2013-07-05 07:01:41 #3 2013-07-06 2013-07-06 06:58:56 2013-07-06 07:01:19 2013-07-06 07:02:20 ?# ?????????????? Vigo #1 2013-07-04 07:04:06 #2 2013-07-05 07:04:42 #3 2013-07-06 07:05:20 A.K. ----- Original Message ----- From: Dominic Roye <dominic.roye at gmail.com> To: R help <r-help at r-project.org> Cc: Sent: Tuesday, July 30, 2013 9:41 AM Subject: [R] Reshape Hello, I try out to create a new form from the below data.frame. I would like to have this form: V3? ? ? ? ? ? ? ? Santiago? ? ? ? ? ? ? ? ? Ourense? ? Vigo? ? Ferrol 2013-07-04? ? 2013-07-04 07:01:04 ...................................... How can i get this?> str(sunrise)'data.frame': 24 obs. of? 3 variables: $ day_frac: Factor w/ 4 levels "Ferrol","Ourense",..: 3 2 4 1 3 2 4 1 3 2 ... $ time? ? : POSIXct, format: "2013-07-04 07:01:04" ... $ V3? ? ? : Factor w/ 6 levels "2013-07-04","2013-07-05",..: 1 1 1 1 2 2 2 2 3 3 ...> sunrise? day_frac? ? ? ? ? ? ? ? time? ? ? ? V3 1? Santiago 2013-07-04 07:01:04 2013-07-04 2? Ourense 2013-07-04 07:00:05 2013-07-04 3? ? ? Vigo 2013-07-04 07:04:06 2013-07-04 4? ? Ferrol 2013-07-04 06:57:38 2013-07-04 5? Santiago 2013-07-05 07:01:41 2013-07-05 6? Ourense 2013-07-05 07:00:41 2013-07-05 7? ? ? Vigo 2013-07-05 07:04:42 2013-07-05 8? ? Ferrol 2013-07-05 06:58:16 2013-07-05 9? Santiago 2013-07-06 07:02:20 2013-07-06 10? Ourense 2013-07-06 07:01:19 2013-07-06 11? ? Vigo 2013-07-06 07:05:20 2013-07-06 12? Ferrol 2013-07-06 06:58:56 2013-07-06 Thanks, Regards ??? [[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.
On 07/30/2013 11:41 PM, Dominic Roye wrote:> Hello, > > I try out to create a new form from the below data.frame. > > I would like to have this form: > > V3 Santiago Ourense Vigo Ferrol > 2013-07-04 2013-07-04 07:01:04 ...................................... > > How can i get this? > >> str(sunrise) > 'data.frame': 24 obs. of 3 variables: > $ day_frac: Factor w/ 4 levels "Ferrol","Ourense",..: 3 2 4 1 3 2 4 1 3 2 > ... > $ time : POSIXct, format: "2013-07-04 07:01:04" ... > $ V3 : Factor w/ 6 levels "2013-07-04","2013-07-05",..: 1 1 1 1 2 2 2 > 2 3 3 ... > >> sunrise > day_frac time V3 > 1 Santiago 2013-07-04 07:01:04 2013-07-04 > 2 Ourense 2013-07-04 07:00:05 2013-07-04 > 3 Vigo 2013-07-04 07:04:06 2013-07-04 > 4 Ferrol 2013-07-04 06:57:38 2013-07-04 > 5 Santiago 2013-07-05 07:01:41 2013-07-05 > 6 Ourense 2013-07-05 07:00:41 2013-07-05 > 7 Vigo 2013-07-05 07:04:42 2013-07-05 > 8 Ferrol 2013-07-05 06:58:16 2013-07-05 > 9 Santiago 2013-07-06 07:02:20 2013-07-06 > 10 Ourense 2013-07-06 07:01:19 2013-07-06 > 11 Vigo 2013-07-06 07:05:20 2013-07-06 > 12 Ferrol 2013-07-06 06:58:56 2013-07-06Hi Dominic, Try this: library(prettyR) sunrise_wide<-stretch_df(sunrise,idvar="V3",to.stretch="time", ordervar="day_frac",include.ordervar=FALSE) names(sunrise_wide)<-c("V3","Ferrol","Ourense","Santiago","Vigo") sunrise_wide Jim