r - Reordering rows in a data.frame? -


all need swap every 2 rows in table... swap every row containing 'chao1' next row, contains 'obs'.

all examples have come accross seem have previous reference that, looking for, think, bit different.

     group.1                  var     s           se     1    cliona celata complex    chao1   800.5933    57.51779 2    cliona celata complex    obs     495.4286    63.07360 3    cliona viridis           chao1   432.5548    35.87778 4    cliona viridis           obs     286.0000    55.32179 5    dysidea fragilis         chao1   694.9129    74.85536 6    dysidea fragilis         obs     357.6667    64.02170 7    phorbas fictitius        chao1   851.6950    57.67145 8    phorbas fictitius        obs     523.2500    23.57905 

thank in advance help!

cheers,

andré

assuming data frame has number of rows can this:

n <- nrow(df) x <- matrix(1:n, ncol=2, byrow=true) y <- x[,2:1] inds <- as.numeric(t(y)) new.df <- df[inds,,drop=false] 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -