[R] Sorting data frame by a string variable
Dimitri Liakhovitski
ld7631 at gmail.com
Tue Jul 17 19:56:00 CEST 2007
I have a data frame MyData with 2 variables.
One of the variables (String) contains a string of letters.
How can I resort MyData by MyData$String (alphabetically) and then
save the output as a sorted data file?
I tried:
o<-order(MyData$String)
SortedData<-rbind(MyData$String[o], MyData$Value[o])
write.table(SortedData,file="Sorted.txt",sep="\t",quote=F, row.names=F)
However, all strings get replaced with digits (1 for the first string,
2 for the second string etc.). How can I keep the strings instead of
digits?
Thank you!
Dimitri
More information about the R-help
mailing list