本文介绍了如何传递所有列,除了一个作为参数setkey()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将列名传递给 setkey(),除了一两个。我可以很容易地做到如下:

  setkey(df,column1,column2,column3,column6, physical = TRUE)

(请注意 column4 column5 )。



但它需要列出除了某些特定列之外的所有列名。我可以得到列表与 colnames(df),但我不知道如何(1)传递到 setkey()

解决方案

setkeyv 它可以接受列名的字符向量,然后使用简单的索引。



例如,位置忽略列

  setkeyv(df,names(df)[ - (4:5)])

通过列名称向量(结合 setdiff )忽略列

  ignore<  -  c(column4,column5)
setkeyv(df,setdiff(names(df),ignore))
/ pre>

I would like to pass column names to setkey() except one or two . I can easily do it like below:

setkey(df, column1, column2, column3, column6, ..., columnN, physical = TRUE)

(please note that column4 and column5 are skipped).

But it requires me to list all column names except some particular columns. I can get list of columns with colnames(df), but I am not sure how to (1) pass it to setkey() and (2) exclude some columns from that list?

解决方案

You could try using setkeyv which can accept a character vector of column names and then use a simple indexing.

For example, ignoring columns by position

setkeyv(df, names(df)[-(4:5)])

Or ignoring columns by vector of column names (combined with setdiff)

ignore <- c("column4", "column5")
setkeyv(df, setdiff(names(df), ignore))

这篇关于如何传递所有列,除了一个作为参数setkey()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 16:11