0
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")

And I want to sort the year column.

df<-df[order(year),]

But I get this error:

Error in order(year) : argument 1 is not a vector

How can I fix this?

Edit:

df<-df[order(df$year),]

Output

"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")
maximusdooku
  • 4,158
  • 7
  • 35
  • 73

0 Answers0