[R] My simple ORDER is broken

William Dunlap wdunlap at tibco.com
Mon Oct 26 20:29:13 CET 2015


Show us the output of
   str(tmp_df)
Your problem could be caused by the Democratic column being
a character or factor column instead of a numeric column:
"71" > "227" but 71 < 227.
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Oct 26, 2015 at 9:08 AM, Jim Burke <javajimburke at gmail.com> wrote:
> 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]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list