[R] [datatable-help] Transform characters to numbers and compare

arun smartpink111 at yahoo.com
Mon Apr 14 02:50:53 CEST 2014

df2 <- df 
df2[] <- lapply(df2,function(x) as.character(as.numeric(factor(x,levels=unique(df$G1))))) 


On Sunday, April 13, 2014 3:36 PM, Sergio.pv <serpalma.v at gmail.com> wrote:
I have a data.frame of two vectors.

df <- data.frame(G1=c("b","a","e","d","c"),
You can see that both vectors have the same characters, but in diferent
order. I want to convert them into numbers and then compare them.

To compare G2 to G1, G1 must be the reference, so the output will be this:

df2 <- data.frame(G1=c("1","2","3","4","5"),
Is there a way to do this?, thanks

View this message in context: http://r.789695.n4.nabble.com/Transform-characters-to-numbers-and-compare-tp4688708.html
Sent from the datatable-help mailing list archive at Nabble.com.
datatable-help mailing list
datatable-help at lists.r-forge.r-project.org

More information about the R-help mailing list