I would like to create a new dataframe from the DateTime column of an existing dataframe and a numeric vector. When I do cbind(x[,1], y) the result is: [1,] 1199370600 12.500 [2,] 1199371200 69.375 [3,] 1199371800 23.750 where the first column you see used to look like: "2008-01-03 08:30:00 Central Standard Time" "2008-01-03 08:40:00 Central Standard Time" "2008-01-03 08:50:00 Central Standard Time" How do I keep the DateTime from getting converted? I've tried as.POSIXct() to convert it back (no luck). -- View this message in context: http://www.nabble.com/When-I-cbind-the-POSIXct-gets-lost-tp15364786p15364786.html Sent from the R help mailing list archive at Nabble.com.
Use data.frame:> tt <- ISOdate(2000, 1:3, 1) > cbind(tt, tt)tt tt [1,] 946728000 946728000 [2,] 949406400 949406400 [3,] 951912000 951912000> data.frame(tt, tt)tt tt.1 1 2000-01-01 12:00:00 2000-01-01 12:00:00 2 2000-02-01 12:00:00 2000-02-01 12:00:00 3 2000-03-01 12:00:00 2000-03-01 12:00:00 On Feb 8, 2008 4:59 PM, Ken Spriggs <ksspriggs at gmail.com> wrote:> > I would like to create a new dataframe from the DateTime column of an > existing dataframe and a numeric vector. When I do cbind(x[,1], y) the > result is: > > [1,] 1199370600 12.500 > [2,] 1199371200 69.375 > [3,] 1199371800 23.750 > > where the first column you see used to look like: > "2008-01-03 08:30:00 Central Standard Time" > "2008-01-03 08:40:00 Central Standard Time" > "2008-01-03 08:50:00 Central Standard Time" > > How do I keep the DateTime from getting converted? I've tried as.POSIXct() > to convert it back (no luck). > > > -- > View this message in context: http://www.nabble.com/When-I-cbind-the-POSIXct-gets-lost-tp15364786p15364786.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
Ken, not sure, but you might try data.frame(whatever1=x[,1],whatever2=y) this should maintain the classes of the vectors. I'm guessing that y and x are of different classes. From ?cbind: "For the default method, a matrix combining the ... argument. The type of a matrix result determined from the highest type of any of the inputs in the hierarchy raw < logical < integer < real < complex < character < list " Matt On Feb 8, 2008 2:59 PM, Ken Spriggs <ksspriggs at gmail.com> wrote:> > I would like to create a new dataframe from the DateTime column of an > existing dataframe and a numeric vector. When I do cbind(x[,1], y) the > result is: > > [1,] 1199370600 12.500 > [2,] 1199371200 69.375 > [3,] 1199371800 23.750 > > where the first column you see used to look like: > "2008-01-03 08:30:00 Central Standard Time" > "2008-01-03 08:40:00 Central Standard Time" > "2008-01-03 08:50:00 Central Standard Time" > > How do I keep the DateTime from getting converted? I've tried as.POSIXct() > to convert it back (no luck). > > > -- > View this message in context: http://www.nabble.com/When-I-cbind-the-POSIXct-gets-lost-tp15364786p15364786.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Matthew C Keller Asst. Professor of Psychology University of Colorado at Boulder www.matthewckeller.com
Seemingly Similar Threads
- Plot timer in a for loop
- Error in cor.default(x1, x2) : missing observations in cov/cor
- Forward only specific identities
- calculating correlation of a Supply/Demand measure and price change (in high frequency time series data)
- enterprise scale redundant Solaris 10/ZFS server providing NFSv4/CIFS