structure(list(year = structure(1:24, .Label = c("1990", "1991",
"1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999",
"2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007",
"2008", "2010", "2011", "2012", "2013", "2009"), class = "factor"),
val = c(8, 3, 1, 17, 5, 9, 6, 7, 3, 15, 11, 6, 2, 11, 15,
11, 15, 1, 14, 2, 15, 4, 6, 0)), .Names = c("year", "val"
), row.names = c(NA, 24L), class = "data.frame")
我想对年份列进行排序。
df<-df[order(year),]
但是我收到了这个错误:
Error in order(year) : argument 1 is not a vector
我该如何解决这个问题?
编辑:
df<-df[order(df$year),]
输出
"1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999",
"2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007",
"2008", "2010", "2011", "2012", "2013", "2009"), class = "factor"),
val = c(8, 3, 1, 17, 5, 9, 6, 7, 3, 15, 11, 6, 2, 11, 15,
11, 15, 1, 14, 2, 15, 4, 6, 0)), .Names = c("year", "val"
), row.names = c(NA, 24L), class = "data.frame")