[R] Remove all factor levels from an R dataframe

John m|@ojpm @end|ng |rom gm@||@com
Tue Nov 10 09:06:22 CET 2020


Hi,

   I would like to sort the following simple dataframe by "year"
(characters), but the factor structure prevents me from doing so. How can I
remove the factor structure? Thanks!

> df1
  year                  country
4 2007             Asia; survey
5 2010 8 countries in E/SE Asia
6 2015                    Ghana
7
8 2000                      US?
> str(df1)
'data.frame': 5 obs. of  2 variables:
 $ year   : Factor w/ 9 levels "2017","2016",..: 4 5 3 6 7
 $ country: Factor w/ 9 levels "Euro Area\\newline Testing the MP
performance of the Euro Area",..: 4 5 6 7 8
> df1[order(-year), ]
Error in order(-year) : object 'year' not found

	[[alternative HTML version deleted]]



More information about the R-help mailing list