【发布时间】:2019-06-04 10:07:53
【问题描述】:
我正在尝试使用 dplyr 展开函数将一列展开为多列。一旦传播,对列的访问就会有一个单引号,我想删除它,因为它妨碍了我过滤数据框
以下是我的代码
# Create Test Frame
testframe = data.frame(name = c("foo-tt.0","bar-tt.0","dd-tt.0","tt-tt.0"),age=as.numeric(c(40,38,10,8)))
#Pivot using name
testframe_pivot <- testframe %>% spread(name,age)
我需要像下面这样访问框架
testframe_pivot$`bar-tt.0` ## I don't want these quotes
[1] 38
为什么我不能得到喜欢(预期输出)
> testframe_pivot$bar-tt.0
[1] 38
我得到了
> testframe_pivot$bar-tt.0
Error: object 'tt.0' not found
我知道这是因为字母和其他字符的混合,但不知道如何摆脱这个错误
后果是……
>name_I_want = c("foo-tt.0")
>select_(testframe_pivot,.dot=name_I_want)
Error in .f(.x[[i]], ...) : object 'foo' not found
【问题讨论】:
-
dplyr::select(testframe_pivot, name_I_want)似乎有效?