我有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_")).提前致谢
我有一个数据框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) 我有一个字符串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)