[R] how to rearrange a dataframe
Laura Rodriguez Murillo
laura.lmurillo at gmail.com
Tue Feb 23 23:27:59 CET 2010
Hi all,
I'd appreciate if anyone can help me with this...
I have a data frame that looks like this:
1 + name1 1 2 3
2 + name2 5 9 10
2 - name3 56 74 93
1 - name4 65 75 98
I need to rearrange this in a way so that the rows with "1" in the
first column, and "-" in the second column; then columns 4 and 6
should switch places. That is, column 6 would be now column 4 and
column 4 would be column 6 (column 5 should stay as column 5)
In the same way, if the first column is "2" and the second is "+",
then the same rearrangement should be done.
Rows with the first two entries 1 + or 2 - should stay in the same order.
This should be done for each row independently.
Thanks a lot for your help!
More information about the R-help
mailing list