-1

I have two data frames called "a1" and "a2" which I brought in by read.csv, with a column called "time" in each for which I used strptime to set the class as POSIXlt.

Prior to trying to merge the data frames I called arrange(a1, time) and arrange(a2, time) to get an oldest to newest order. I then tried to call ahu1 <- merge(a1, a2) to start putting it all together and got the following error:

Error in sort.list(bx[m$xi]) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?

Calling str(a1) and str(a2) verifies that both are in fact data frames, and they have the same total number of observations. What am I missing or doing wrong?

structure(list(time = structure(list(sec = c(0, 0, 0, 0, 0, 0), min = c(0L, 15L, 30L, 45L, 0L, 15L), hour = c(10L, 10L, 10L, 10L, 11L, 11L), mday = c(24L, 24L, 24L, 24L, 24L, 24L), mon = c(1L, 
1L, 1L, 1L, 1L, 1L), year = c(114L, 114L, 114L, 114L, 114L, 114L), wday = c(1L, 1L, 1L, 1L, 1L, 1L), yday = c(54L, 54L, 54L, 54L, 54L, 54L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L), zone = c("MST", 
"MST", "MST", "MST", "MST", "MST"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_)), .Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst", "zone", "gmtoff"), class = c("POSIXlt", "POSIXt")), status.sf = c("TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE"), status.rf = c("TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE"), cfm.oa = c(1397.6, 343, 1265, 1500, 744.5, 1261.6), cfm.ra = c("2364.8", "3067.4", "2073.9", "2727.4", "2561.2", "2032.4"), temp.ra = c(68.6, 67.6, 69.1, 69.7, 67.9, 69), temp.ma = c(65.6, 65.8, 66.8, 67.9, 66.5, 68.2), temp.sa = c(51.1, 66.4, 68.6, 51.2, 67.3, 68), ductstatic = c(0.25, 0.25, 0.25, 0.47, 0.27, 0.25), fault.hum = c("FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE"), fltpress = c(0.15, 0.12, 0.12, 0.22, 0.13, 0.13), fault.smoke = c("FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE")), .Names = c("time", "status.sf", "status.rf", "cfm.oa", "cfm.ra", "temp.ra", "temp.ma", "temp.sa", 
"ductstatic", "fault.hum", "fltpress", "fault.smoke"), row.names = c(NA, 6L), class = "data.frame")



structure(list(time = structure(list(sec = c(0, 0, 0, 0, 0, 0), min = c(0L, 15L, 30L, 45L, 0L, 15L), hour = c(10L, 10L, 10L, 10L, 11L, 11L), mday = c(24L, 24L, 24L, 24L, 24L, 24L), mon = c(1L, 1L, 1L, 1L, 1L, 1L), year = c(114L, 114L, 114L, 114L, 114L, 114L), wday = c(1L, 1L, 1L, 1L, 1L, 1L), yday = c(54L, 54L, 54L, 54L, 54L, 54L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L), zone = c("MST", "MST", "MST", "MST", "MST", "MST"), gmtoff = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_)), .Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst", "zone", "gmtoff"), class = c("POSIXlt", "POSIXt")), occpt = c("TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE"), max.dmprpos = c(77, 63, 71, 93, 63, 71), mode.ecm = c("TRUE", "TRUE", "TRUE", "TRUE", "TRUE", "TRUE"), mode.dehum = c("TRUE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE"), spt.sa = c("53", "66", "66", "66", "66", "66"
), spt.ductstatic = c("0.27", "0.25", "0.25", "0.57", "0.25", "0.25"), mode.co2 = c("FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE"), mode.hum = c("FALSE", "FALSE", "FALSE", "FALSE", "FALSE", "FALSE"), max.runreqt = c("0", "0", "0", "0", "0", "0"), max.vavco2 = c("427", "429", "427", "414", "417", "406"), max.vavrhv = c("59", "56.4", "54.9", "56.1", "53.3", "50.1"), cfm.vavtot = c("2711", "2383.6", 
"2395.8", "3702.9", "2449.8", "2388.4"), spt.cfm.ra = c("2461", "2133", "2144.3", "3433.7", "2198.8", "2139.3")), .Names = c("time", "occpt", "max.dmprpos", "mode.ecm", "mode.dehum", "spt.sa", "spt.ductstatic", "mode.co2", "mode.hum", "max.runreqt", "max.vavco2", "max.vavrhv", "cfm.vavtot", "spt.cfm.ra"), row.names = c(NA, 6L), class = "data.frame")
Scott Ritchie
  • 10,293
  • 3
  • 28
  • 64
Michael
  • 1
  • 2
  • Could you edit in the result of `dput(head(a1))` and `dput(head(a2))`, which would make your issue [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? (Also, please don't worry that I edited out the first sentence of your post; it's just Stack Exchange's policy to avoid sentences like that). It would also be a good idea to show your code in multiple lines (you can indent it with four characters, as I've done with your error message) rather than mixing it in with the text. – David Robinson May 10 '14 at 00:43
  • Where does `arrange` come from? Doesn't seem to be in base. – MrFlick May 10 '14 at 00:45
  • It's from plyr (should add `library(plyr)` to the question above). However, the question doesn't explicitly state whether he did `a1 <- arrange(a1, time)` (which would work) or just `arrange(a1, time)` (which wouldn't do anything) – David Robinson May 10 '14 at 00:49
  • `?arrange` : No documentation for ‘arrange’ in specified packages and libraries: you could try ‘??arrange’ – IRTFM May 10 '14 at 01:44
  • `?plyr::arrange` will give you the help file – James King May 10 '14 at 01:49
  • I assigned a1 the value of the arrange call: a1 <- arrange(a1, time) and again for a2. – Michael May 16 '14 at 16:08
  • Actually, I think this may have had something to do with how I transformed my time column. I just removed a1 and a2 and re-read the csv files back in. I tried merging them without first changing the time column from chr to date/time, and it worked with no problem. – Michael May 16 '14 at 16:14

1 Answers1

0

At the moment anyway the two data objects have exactly the same number of tows and the date-times are the same. So it would be a simple step to just use cbind(). There's no matching of the time columns.

 cbind(a1, a2[-1])

                 time status.sf status.rf cfm.oa cfm.ra temp.ra temp.ma temp.sa
1 2014-02-24 10:00:00      TRUE      TRUE 1397.6 2364.8    68.6    65.6    51.1
2 2014-02-24 10:15:00      TRUE      TRUE  343.0 3067.4    67.6    65.8    66.4
3 2014-02-24 10:30:00      TRUE      TRUE 1265.0 2073.9    69.1    66.8    68.6
4 2014-02-24 10:45:00      TRUE      TRUE 1500.0 2727.4    69.7    67.9    51.2
5 2014-02-24 11:00:00      TRUE      TRUE  744.5 2561.2    67.9    66.5    67.3
6 2014-02-24 11:15:00      TRUE      TRUE 1261.6 2032.4    69.0    68.2    68.0
  ductstatic fault.hum fltpress fault.smoke occpt max.dmprpos mode.ecm
1       0.25     FALSE     0.15       FALSE  TRUE          77     TRUE
2       0.25     FALSE     0.12       FALSE  TRUE          63     TRUE
3       0.25     FALSE     0.12       FALSE  TRUE          71     TRUE
4       0.47     FALSE     0.22       FALSE  TRUE          93     TRUE
5       0.27     FALSE     0.13       FALSE  TRUE          63     TRUE
6       0.25     FALSE     0.13       FALSE  TRUE          71     TRUE
  mode.dehum spt.sa spt.ductstatic mode.co2 mode.hum max.runreqt max.vavco2
1       TRUE     53           0.27    FALSE    FALSE           0        427
2      FALSE     66           0.25    FALSE    FALSE           0        429
3      FALSE     66           0.25    FALSE    FALSE           0        427
4      FALSE     66           0.57    FALSE    FALSE           0        414
5      FALSE     66           0.25    FALSE    FALSE           0        417
6      FALSE     66           0.25    FALSE    FALSE           0        406
  max.vavrhv cfm.vavtot spt.cfm.ra
1         59       2711       2461
2       56.4     2383.6       2133
3       54.9     2395.8     2144.3
4       56.1     3702.9     3433.7
5       53.3     2449.8     2198.8
6       50.1     2388.4     2139.3
IRTFM
  • 258,963
  • 21
  • 364
  • 487