我想准时加入两张桌子。输入文件有一个hh:mm:ss列和一个am / pm列。我似乎已成功创建了一个新的列与日期信息,但我无法加入它。错误信息对我没有意义,也没有指向我给它的任何内容。
此:
t1 <- read.table("~/SEQ-1066/sar.r.54043.txt",header=TRUE)
t2 <- read.table("~/SEQ-1066/sar.q.54043.txt",header=TRUE)
t1$pt <- strptime(paste(t1$time, t1$AM),"%I:%M:%S %p")
t2$pt <- strptime(paste(t2$time, t2$AM),"%I:%M:%S %p")
t <- merge(x=t1,y=t2,by="pt")
结果:
> t1 <- read.table("~/SEQ-1066/sar.r.54043.txt",header=TRUE)
> t2 <- read.table("~/SEQ-1066/sar.q.54043.txt",header=TRUE)
> t1$pt <- strptime(paste(t1$time, t1$AM),"%I:%M:%S %p")
> t2$pt <- strptime(paste(t2$time, t2$AM),"%I:%M:%S %p")
> t <- merge(x=t1,y=t2,by="pt")
Error in sort.list(bx[m$xi]) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
感谢R有这么容易理解的错误消息。
答案 0 :(得分:3)
显然strptime
的数据类型不可排序或可用作连接索引,因此使用as.POSIXct
强制转换为<{1}}。
t1 <- read.table("~/SEQ-1066/sar.r.54043.txt",header=TRUE)
t2 <- read.table("~/SEQ-1066/sar.q.54043.txt",header=TRUE)
t1$pt <- as.POSIXct(strptime(paste(t1$time, t1$AM),"%I:%M:%S %p"), tz = "GMT")
t2$pt <- as.POSIXct(strptime(paste(t2$time, t2$AM),"%I:%M:%S %p"), tz = "GMT")
t <- merge(x=t1,y=t2,by="pt")
找到了实际解决方案here,谢谢Henrique Dallazuanna。