[R] Order of columns(variables) in dataframe

2008-07-20 Thread Daniel Wagner
Dear R experts,   I have a dataframe with 4 columns (variables). I want to redorder (or reposition) these columns on the basis of a value in its last row. e.g.   df1-data.frame( v1= c(2,3,1,9,5), v2=c(8,5,12,4,11), v3=c(7,8,2,6,9), v4=c(1,4,6,3,6))    df1    v1 v2 v3 v4 1  2  8  7  1

Re: [R] Order of columns(variables) in dataframe

2008-07-20 Thread jim holtman
Is this what you want: x - read.table(textConnection( v1 v2 v3 v4 + 1 2 8 7 1 + 2 3 5 8 4 + 3 1 12 2 6 + 4 9 4 6 3 + 5 5 11 9 6), header=TRUE) closeAllConnections() # order by the last row x[, order(unlist(x[5,]), decreasing=TRUE)] v2 v3 v4 v1 1 8 7 1 2 2 5 8 4 3

Re: [R] Order of columns(variables) in dataframe

2008-07-20 Thread Dimitris Rizopoulos
try this: df1 - data.frame(v1 = c(2,3,1,9,5), v2 = c(8,5,12,4,11), v3 = c(7,8,2,6,9), v4 = c(1,4,6,3,6)) vals - unlist(df1[5, ]) df1[order(vals, decreasing = TRUE)] I hope it helps. Best, Dimitris Dimitris Rizopoulos Biostatistical Centre School of Public Health Catholic University

Re: [R] Order of columns(variables) in dataframe

2008-07-20 Thread Ted Harding
On 20-Jul-08 11:32:14, Daniel Wagner wrote: Dear R experts, I have a dataframe withÂ_4 columns (variables). I want to redorder (or reposition) these columns on the basis of a value in its last row. e.g. df1-data.frame( v1= c(2,3,1,9,5), v2=c(8,5,12,4,11), v3=c(7,8,2,6,9), v4=c(1,4,6,3,6))