我想更改我的数据框中列的位置,如此处所述。但我不知道为什么这不起作用。见下文...
df1 <- structure(list(S01 = c(51L, 82L, 72L, 79L, 2L, 86L, 33L, 56L,3L, 35L), S02 = c(49L, 33L, 59L, 68L, 35L, 45L, 22L, 18L, 67L, 79L), S03 = c(109L, 103L, 112L, 100L, 102L, 110L, 106L, 105L,107L, 111L), S04 = c(136L, 160L, 46L, 298L, 133L, 96L, 224L, 82L, 238L, 283L), S05 = c(189L, 168L, 178L, 129L, 128L, 72L,77L, 171L, 4L, 65L)), .Names = c("S01", "S02", "S03", "S04", "S05"), row.names = c(NA, -10L), class = "data.frame")
str(df1)
correctCol <- c('S01','S03','S05','S02','S04') # this will be generated by a function in turn
df.correct <- subset[df1,select=correctCol]
它抛出以下错误:
Error in subset[df1, select = correctCol] :
object of type 'closure' is not subsettable
编辑
是的,我错了,因为我没有看到它应该是(
而不是[
这有效
df.correct <- subset(df1,select=correctCol)