我想将一个列列表传递给ranging函数。我尝试使用enquos函数
column.names
column.names <- c(colnames(SQL_Table))
column.names
[1] "plan" "class" "gender" "band" "marital_status" "acceleration" "extension"
[8] "inflation" "iss_age" "cell" "dur" "db_perk" "accel_perk" "ext_perk"
[15] "attage"
我的代码是
column.names <- c(colnames(SQL_Table))
arrange.remove <- c("cell","db_perk","accel_perk","ext_perk","attage","db_perk_compare")
arrange.columns <- setdiff(column.names,remove)
arrange_quo <- enquos(arrange.columns)
SQL_Table %>%
arrange(!!arrange_quo)
我遇到错误
Error: incorrect size (1) at position 1, expecting : 144000
答案 0 :(得分:0)
根据此post,您可以使用构造:
cols.names <- colnames(df)
df[do.call('order', df[cols.names]), ]
df[do.call('order', c(df[cols.names], list(decreasing=TRUE))), ]
因此,在使用管道的情况下:
df %>%
.[do.call("order", .[cols.names]), ]
但是对于单列名称也可以:
col.name <- "column.name"
df %>%
arrange(.[[get("col.name")]])