[R] Data management problem (reorder rows in dataframe by text flag)
Christian Bieli
christian.bieli at unibas.ch
Wed Feb 7 13:39:46 CET 2007
how about:
t.d <- data.frame(col1=c("31*","0","102*","71*","31","66","47"),
col2=c("66","0*","66","80","2*","31*","38*"),
stringsAsFactors = FALSE)
t.x <- apply(t.d,1,function(x) x[order(unlist(x)==grep("\\*$",
unlist(x),value=TRUE))])
t.d2 <- data.frame(col1=t.x[1,],col2=sub("\\*$","",t.x[2,]))
greets
christian
--
Christian Bieli, project assistant
Institute of Social and Preventive Medicine
University of Basel, Switzerland
Steinengraben 49
CH-4051 Basel
Tel.: +41 61 270 22 12
Fax: +41 61 270 22 25
christian.bieli at unibas.ch
www.ispm-unibasel.ch
More information about the R-help
mailing list