[R] My simple ORDER is broken

Jim Burke javajimburke at gmail.com
Mon Oct 26 17:08:03 CET 2015


tmp_df[order(tmp_df$Democratic),]
   Precinct Last.Name Democratic Republican.Total Registered.Voters
2      2904 Open Seat          1                0                15
NA     2903 Open Seat        227              245              2035
3      2905 Open Seat         71              202               497


tmp_df[order(tmp_df[3]),]
   Precinct Last.Name Democratic Republican.Total Registered.Voters
2      2904 Open Seat          1                0                15
NA     2903 Open Seat        227              245              2035
3      2905 Open Seat         71              202               497

> tmp_df$Democratic[order(tmp_df$Democratic)]
[1] "1"   "227" "71"

What am I doing wrong? I would like the order below. I suspect the problem
lies with that NA to the left that R inserted somewhere along the line. So
how to reorder dataframe rows? Or get rid of that NA?
2      2904 Open Seat          1                0                15
3      2905 Open Seat         71              202               497
NA     2903 Open Seat        227              245              2035

Thanks,
Jim Burke

	[[alternative HTML version deleted]]



More information about the R-help mailing list