小编Bar*_*art的帖子

R dplyr 以编程方式识别列

对于某些对象,属性标识特殊列,例如对象中的几何列sf。为了在其中进行一些计算,dplyr最好能够轻松识别这些列。我正在寻找一种方法来创建一个有助于识别此列的函数。在下面的示例中,我可以创建一个函数来标识该列,但我仍然需要使用rlang拼接运算符 ( !!!)。

\n
require(sf)\nrequire(dplyr)\nn<-4\ndf = st_as_sf(data.frame(x = 1:n, y = 1:n, cat=gl(2,2)), coords = 1:2, crs = 3857) %>% group_by(cat)\n# this is the example I start from however the geometry column is not guaranteed to have that name\ndf %>% mutate(d=st_distance(geometry, geometry[row_number()==1]))\n#> Simple feature collection with 4 features and 2 fields\n#> Geometry type: POINT\n#> Dimension:     XY\n#> Bounding box:  xmin: 1 ymin: 1 xmax: 4 ymax: 4\n#> Projected CRS: WGS 84 / Pseudo-Mercator\n#> # …
Run Code Online (Sandbox Code Playgroud)

r dplyr nse tidyeval

5
推荐指数
1
解决办法
138
查看次数

标签 统计

dplyr ×1

nse ×1

r ×1

tidyeval ×1