What is the fastest / best way to convert a large number of columns into numerical factors?
I used the following code but my data appears to be re-ordered.
& gt; Head (stats [, 1: 2]) RK team 1 1 Washington Capitolas * 2 2 San Jose Shark * 3 3 Chicago Blackhawks * 4 Phoenix Coyotes * 5 5 New Jersey Devils * 6 6 for Vancouver Canucks * (Stats [, 1: 2]) RK Team 1 2 Washington Capitol (Stats [, I]] [stats [, I] & lt; - as.numeric (statistics [, I])}> Head * 2 13 Saini Jose Shark * 3 24 Chicago Blackhawks * 4 26 Phoenix Coyotes * 5 27 New Jersey Devils * 6 28 Vancouver Canucks *
What is the best way, There is a lack of nomination for each column:
df $ colname & lt; - as.numeric (ds $ colname)
as.numeric (x)
R level factor
x if you want to retain the numbers that want to preserve the level of factor (instead of their internal representation), then you get to the right As an anecdote, it has to be converted to characters in the first as.character ()
. Your for
loop is appropriate as a application.
The call may be slightly more readable, what is the purpose of code, just change this line Do:
Statistics [, I]
to read
statistics [, i] & lt; - as.numeric (as.character (statistics [, ii]))
This is in RFQ.
HH
Comments
Post a Comment