Andrew Anglemyer
2011-Feb-18 05:53 UTC
[R] problem with rbind when data frame contains an date-time variable "POSIXt" "POSIXlt"
I'm trying to rbind two data frames, both with the same columns names. One of the columns is a variable with date-time and this variable is causing the rbind to fail--giving the error "Error in names(value[[jj]])[ri] <- nm : 'names' attribute [7568] must be the same length as the vector [9]" Is there a way to stack or rbind these two data frames even with this extended date-time variable? The class of event.date.time in each data frame is POSIXt POSIXlt. x ID event.date.time 1 2009-07-23 00:20:00 2 2009-08-18 16:25:00 3 2009-08-13 08:30:00 y ID event.date.time 4 2009-08-25 10:25:00 5 2009-08-10 06:20:00 6 2009-10-09 08:20:00 I would like to get z ID event.date.time 1 2009-07-23 00:20:00 2 2009-08-18 16:25:00 3 2009-08-13 08:30:00 4 2009-08-25 10:25:00 5 2009-08-10 06:20:00 6 2009-10-09 08:20:00 I've looked at stripping the dates and times, but it would be really helpful for my purposes to keep the extended variable date-time variable (have to eventually get 24 hours from baseline.date.time). thanks for any and all help! Andy [[alternative HTML version deleted]]
Bill.Venables at csiro.au
2011-Feb-18 06:21 UTC
[R] problem with rbind when data frame contains an date-time variable "POSIXt" "POSIXlt"
The solution is probably to make the data-time columns POSIXct:> x <- read.table(textConnection("+ ID event.date.time + 1 '2009-07-23 00:20:00' + 2 '2009-08-18 16:25:00' + 3 '2009-08-13 08:30:00' + "), header = TRUE)> y <- read.table(textConnection("+ ID event.date.time + 4 '2009-08-25 10:25:00' + 5 '2009-08-10 06:20:00' + 6 '2009-10-09 08:20:00' + "), header = TRUE)> closeAllConnections() > > x <- within(x,+ event.date.time <- as.POSIXct(as.character(event.date.time), + format = "%Y-%m-%d %H:%M:%S"))> y <- within(y,+ event.date.time <- as.POSIXct(as.character(event.date.time), + format = "%Y-%m-%d %H:%M:%S"))> z <- rbind(x, y) > zID event.date.time 1 1 2009-07-23 00:20:00 2 2 2009-08-18 16:25:00 3 3 2009-08-13 08:30:00 4 4 2009-08-25 10:25:00 5 5 2009-08-10 06:20:00 6 6 2009-10-09 08:20:00>No problems. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Andrew Anglemyer Sent: Friday, 18 February 2011 3:54 PM To: r-help at r-project.org Subject: [R] problem with rbind when data frame contains an date-time variable "POSIXt" "POSIXlt" I'm trying to rbind two data frames, both with the same columns names. One of the columns is a variable with date-time and this variable is causing the rbind to fail--giving the error "Error in names(value[[jj]])[ri] <- nm : 'names' attribute [7568] must be the same length as the vector [9]" Is there a way to stack or rbind these two data frames even with this extended date-time variable? The class of event.date.time in each data frame is POSIXt POSIXlt. x ID event.date.time 1 2009-07-23 00:20:00 2 2009-08-18 16:25:00 3 2009-08-13 08:30:00 y ID event.date.time 4 2009-08-25 10:25:00 5 2009-08-10 06:20:00 6 2009-10-09 08:20:00 I would like to get z ID event.date.time 1 2009-07-23 00:20:00 2 2009-08-18 16:25:00 3 2009-08-13 08:30:00 4 2009-08-25 10:25:00 5 2009-08-10 06:20:00 6 2009-10-09 08:20:00 I've looked at stripping the dates and times, but it would be really helpful for my purposes to keep the extended variable date-time variable (have to eventually get 24 hours from baseline.date.time). thanks for any and all help! Andy [[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.