排列功能:lubridate和dplyr R之间的冲突 [英] Arrange function: Conflict between lubridate and dplyr R
问题描述
我想用 dplyr
中的 arrange
函数重新排列df.问题是,当我有另一列(比如说v2)与我要安排df的列不同时,这两个软件包似乎有冲突:
I want to rearrange a df with the function arrange
from dplyr
. The problem is that seems that these two packages have a conflict when I have another column (let's say v2) distinct from the column I want to arrange the df:
library(dplyr)
library(lubridate)
start_dates <- as.Date(1:10, origin = "2018-01-01")
my_df <- data.frame(x = 10:1, y = interval(start_dates, start_dates + 1),
z=c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J"))
my_df %>% arrange(z)
range_impl(.data,点)中的错误:列
y
类当前不支持lubridate的Period和Interval.
Error in arrange_impl(.data, dots) : Column
y
classes Period and Interval from lubridate are currently not supported.
如何订购数据框?谢谢你.
How I can order my dataframe? Thank you in advanced.
推荐答案
我不会将其本身称为冲突",只是一个软件包不支持另一个软件包的功能.
I wouldn't call this a "conflict" per se, just one package not supporting the features of another.
如果 dplyr
的 arrange()
不支持 Interval
类,则只需使用 order()
像往常一样:
If dplyr
's arrange()
doesn't support Interval
classes, just use order()
like normal:
library(dplyr)
library(lubridate)
start_dates <- as.Date(1:10, origin = "2018-01-01")
my_df <- data.frame(x = 10:1, y = interval(start_dates, start_dates + 1))
my_df %>% arrange(y)
range_impl(.data,点)中的错误:
当前不支持y列类lubridate的Period和Interval.
Error in arrange_impl(.data, dots) :
Column `y` classes Period and Interval from lubridate are currently not supported.
my_df[order(my_df$y), ]
# x y
# 1 10 2018-01-02 UTC--2018-01-03 UTC
# 2 9 2018-01-03 UTC--2018-01-04 UTC
# 3 8 2018-01-04 UTC--2018-01-05 UTC
# 4 7 2018-01-05 UTC--2018-01-06 UTC
# 5 6 2018-01-06 UTC--2018-01-07 UTC
# 6 5 2018-01-07 UTC--2018-01-08 UTC
# 7 4 2018-01-08 UTC--2018-01-09 UTC
# 8 3 2018-01-09 UTC--2018-01-10 UTC
# 9 2 2018-01-10 UTC--2018-01-11 UTC
# 10 1 2018-01-11 UTC--2018-01-12 UTC
注意
为将来参考,我会认真对待 OTStats 的警告-通常没有示例数据,很难做到这一点别人来帮助你.我会查看如何制作出色的R可再现示例
Note
For future reference, I would take seriously the admonition by OTStats -- often without example data it is very difficult for others to help you. I would check out How to Make a Great R Reproducible Example.
这篇关于排列功能:lubridate和dplyr R之间的冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!