本文介绍了将数据帧与dplyr中的difftime列连接起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个完全相同列的数据帧,我试图使用dplyr :: union将它们连接起来。 union(df.3,df.4)
但是,我收到错误:
$ b,无法加入> run.time'x'run.time'
$ b
由于 run.time
列是相同的类型,为什么我会收到此错误?
class(df.4 $ run.time)
[1]difftime
> class(df.3 $ run.time)
[1]difftime
>
我知道我可以使用 rbind
做连接,但我很好奇为什么 union
不起作用。
解决方案
我觉得需要提醒你:
我将非常谨慎使用 rbind
您的列是 difftime
。考虑这个例子:
now< - Sys.time()
foo< - data.frame = now + 10 - now)
bar< - data.frame(X = now + 120 - now)
foo
## X
## 1 10秒
bar
## X
## 1 2分钟
rbind(foo,bar)
## X
## 1 10 secs
## 2 2 secs !!!
rbind(bar,foo)
## X
## 1 2分钟
## 2 10分钟!
I have two data frames with exactly the same columns and I'm trying to concatenate them together using dplyr::union.
union(df.3, df.4)
However, I get the error:
Being that the run.time
columns are the same type, why am I getting this error?
class(df.4$run.time)
[1] "difftime"
> class(df.3$run.time)
[1] "difftime"
>
I know I can just use rbind
to do the concatenation, but I was curious why union
doesn't work.
解决方案
I feel the need to warn you about this:
I would be very cautious about using rbind
when one of your columns is a difftime
. Consider this example:
now <- Sys.time()
foo <- data.frame(X = now+10 - now)
bar <- data.frame(X = now+120 - now)
foo
## X
## 1 10 secs
bar
## X
## 1 2 mins
rbind(foo, bar)
## X
## 1 10 secs
## 2 2 secs !!!
rbind(bar, foo)
## X
## 1 2 mins
## 2 10 mins !!!
这篇关于将数据帧与dplyr中的difftime列连接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!