I have a programming doubt in R and I have no idea how to solve it after spending hours looking at potential responses on the internet and on Stack Overflow.
I have a factor variable in a column of a data.frame that looks like this:
Columnname
agsgssg
agsgssg
agsgssg
adgatata
ahagha
ahagha
ahagha
ahagha
aghaatah
ghssghs
ghssghs
ghssghs
The factor variable is not directly transformable into numeric with as.numeric(as.character()) because each level is a string, not a number.
What I would need is
Columnname Numericcolumnname
agsgssg 1
agsgssg 1
agsgssg 1
adgatata 2
ahagha 3
ahagha 3
ahagha 3
ahagha 3
aghaatah 4
ghssghs 5
ghssghs 5
ghssghs 5
I have tried several approaches including using levels() for the factor variable, using freq() for the factor variable trying to figure out how many rows there are for each level and then making a repeated number for each level of the factor with several "for" loops without success.
I feel that it should have a very simple solution, I am just not figuring it out.
Thank you for your consideration
df$Numericcolumnname <- as.numeric(Columnname)- Pierre Lmatch(df$Columnname, unique(df$Columnname))? - talatas.numeric(x). - Pierre L