[R] data frame move columns

David Winsemius dwinsemius at comcast.net
Wed Apr 28 17:28:26 CEST 2010


On Apr 28, 2010, at 11:14 AM, arnaud Gaboury wrote:

> Dear group,
>
> Here is my df:
>
> avprix <-
> structure(list(DESCRIPTION = c("CORN Jul/10", "CORN May/10",
> "ROBUSTA COFFEE (10) Jul/10", "SOYBEANS Jul/10", "SPCL HIGH GRADE  
> ZINC USD",
>
> "STANDARD LEAD USD"), prix = c(-1.5, -1082, 11084, 1983.5, -2464,
> -118), quantity = c(0, -3, 8, 2, -1, 0), fees = c(-8.64, -30.24,
> -26.4, -25.92, -37.5, -25)), .Names = c("DESCRIPTION", "prix",
> "quantity", "fees"), row.names = c(NA, -6L), class = "data.frame")
>
> I want to group together all the rows with quantity=0.
>
> This following line does the job :
>
>> avprix<-rbind(,avprix[avprix$quantity==0,]).
>
> I was just wandering if  there is a more "academic" way to write it?

? order

avprix[order(avprix$quantity),]

Or if you want them at the end ... since TRUE > FALSE:

avprix[order(avprix$quantity==0),]

>
> TY for advice.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list