[R] Convert data frame entries to numbers

2009-10-19 Thread John
Hello, I figure this is quite a simple problem really, but since I'm quite new to R I need to ask: If I have a data frame: str(test) : $ classcol: Factor w/ 3 levels 1,2,3 How do I convert the entries in this column to numbers. I.e., I want to be abl to do simple calculations like

Re: [R] Convert data frame entries to numbers

2009-10-19 Thread joris meys
2 problems : test seems to be a data frame or list with one variable. So you have to specify : as.numeric(test$classcol) But this will make the internal factor levels the real values, not the numbers you specified. What you need, is as.numeric(as.character(test$classcol)) Cheers Joris On Mon,

Re: [R] Convert data frame entries to numbers

2009-10-19 Thread Peter Ehlers
joris meys wrote: 2 problems : test seems to be a data frame or list with one variable. So you have to specify : as.numeric(test$classcol) But this will make the internal factor levels the real values, not the numbers you specified. What you need, is as.numeric(as.character(test$classcol))