我需要gather_
在数据帧的所有列上,除了一个。例如:我怎样才能收集所有专栏,而不是一个专栏?
# I want to generate a dataframe whose column names are the letters of the alphabet. If you know of a simpler way, let me know!
foo <- as.data.frame(matrix(runif(100), 10, 10))
colnames(foo) <- letters[1:10]
现在,假设我要收集所有列,除了e
列。这是行不通的:
mycol <- "e"
foo_melt <- gather_(foo, key = "variable", value = "value", -mycol)
#Error in -mycol : invalid argument to unary operator
这将:如果你问我
column_list <- colnames(foo)
column_list <- column_list[column_list != mycol]
foo_melt <- gather_(foo, key = "variable", value = "value", column_list)
看起来颇为费解。没有更简单的方法吗?
一种选择是'setdiff'即'gather_(FOO,键= “可变”,值= “值”,setdiff(名称(富),mycol))' – akrun