小编Edu*_*Edu的帖子

反转到dplyr中的starts_with()

我有df这个变量具有以下名称:

> names(df)
 [1] "local authority: district / unitary (as of April 2015)" "oslaua"                                                
 [3] "December 2014"                                          "X__1"                                                  
 [5] "March 2015"                                             "X__2"                                                  
 [7] "June 2015"                                              "X__3"
Run Code Online (Sandbox Code Playgroud)

我知道我可以选择那些X__以函数开头的变量df %>% select(starts_with("X_")).

我的问题是,是否会有一个函数可以精确选择那些不以那些开头的变量X__.输出应该给出类似的东西df %>% select(! starts_with("X_")).提前致谢

r dplyr

8
推荐指数
1
解决办法
832
查看次数

使用 dplyr 对分组数据进行 cumsum

我有一个数据框df(可以在此处下载)引用公司登记册,如下所示:

    Provider.ID        Local.Authority month year entry exit total
1  1-102642676           Warwickshire    10 2010     2    0     2
2  1-102642676                   Bury    10 2010     1    0     1
3  1-102642676                   Kent    10 2010     1    0     1
4  1-102642676                  Essex    10 2010     1    0     1
5  1-102642676                Lambeth    10 2010     2    0     2
6  1-102642676            East Sussex    10 2010     5    0     5
7  1-102642676       Bristol, City of    10 2010     1    0     1
8  1-102642676              Liverpool    10 2010     1    0     1
9 …
Run Code Online (Sandbox Code Playgroud)

r cumsum dplyr

3
推荐指数
1
解决办法
3235
查看次数

R在字符串中提取重复的单词

我有一个字符串a,并b认为我的组合data.我的目的是获得一个包含重复单词的新变量.

    a = c("the red house av", "the blue sky", "the green grass")
    b = c("the house built", " the sky of the city", "the grass in the garden")

data = data.frame(a, b)
Run Code Online (Sandbox Code Playgroud)

基于这个答案,我可以得到那些重复的逻辑duplicated()

data = data%>% mutate(c = paste(a,b, sep = " "),
                     d = vapply(lapply(strsplit(c, " "), duplicated), paste, character(1L), collapse = " "))
Run Code Online (Sandbox Code Playgroud)

然而,我无法获得这些词语.我想要的数据应该是这样的

> data.1
                 a                       b         d
1 the red house av         the house built the …
Run Code Online (Sandbox Code Playgroud)

string r duplicates

2
推荐指数
1
解决办法
612
查看次数

标签 统计

r ×3

dplyr ×2

cumsum ×1

duplicates ×1

string ×1