[R] Order sapply

Rui Barradas rui1174 at sapo.pt
Sat Apr 7 19:04:18 CEST 2012


Hello,

>
>    I have the following code, but it seems that something must be doing
> wrong, because it is giving the results I want.
> The idea is to create segments while the value of Commutation is less than
> 1000.
> for example, from the small set of data below 
> 

I believe that code was mine, from an answer to a post of yours. 

> 
> I think there is a problem in the order of the different blocks, I don’t
> understand, how is that data are organized.
> The idea is to keep the organization of the file near the original.
> 

Maybe that's not possible. The order is given by 'split'.
But you can make it "near the original", if you put comm1000 last in the
split list.

# This line should be changed
# result <- split(df1[!inx, ], list(comm1000[!inx], df1$v_source[!inx],
df1$v_destine[!inx]))
# to this one.
result <- split(df1[!inx, ], list(df1$v_source[!inx], df1$v_destine[!inx],
comm1000[!inx]))

You can also use Sarah's suggestion and have the entire results data frame
ordered


inx_ord <- with(results_user, order(user, v_source, v_destine))
results_user[inx_ord, ]


Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/Order-sapply-tp4537496p4539748.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list