小编aim*_*r21的帖子

R - 链接 data.table 操作的最佳实践

到处搜索,但没有找到任何用于安排 data.table 链式代码的一般准则,这些代码可能跨越多行以提高可读性。

拿f.ex。(仅用于说明目的的玩具示例)

iris.dt[sepal.length > 5 & sepal.width > 3 & petal.length > 2 & petal.width > 2 & species == "virginica"] 
Run Code Online (Sandbox Code Playgroud)

由于这一切都对应于相同的参数 (dt[i]),因此将其拆分为多行很容易,我只会这样做:

iris.dt[sepal.length > 5 & 
        sepal.width  > 3 & 
        petal.length > 2 & 
        petal.width  > 2 & 
        species == "virginica"] 
Run Code Online (Sandbox Code Playgroud)

或者

iris.dt[sepal.length > 5 & 
          sepal.width  > 3 & 
          petal.length > 2 & 
          petal.width  > 2 & 
          species == "virginica"] 
Run Code Online (Sandbox Code Playgroud)

但是拿f.ex。像这样。您将如何清理此代码片段以及在哪里缩进/换行?注意:这只是一个关于长 data.table 链式代码块在实践中的样子的玩具示例。

    iris.dt[, id := 1:.N, by = species][, comb_area_sepal := (sepal.length * …
Run Code Online (Sandbox Code Playgroud)

r data.table

4
推荐指数
1
解决办法
71
查看次数

标签 统计

data.table ×1

r ×1