0

So I have a very large dataset, which I'm trying to look at in R, with most of the columns having words in them.

I want to turn this character data into meaningful values that I can preform calculations on.

So I sub values for numeric data for example:

mydataset<-sub("Least Concern",1, mydataset)

All the numbers are between 1-7.

I then checked that all my sub values are what I expected and they are.

I then convert it to a dataframe and then convert each column like so:

asnumbers["currentstatus"]<-(as.numeric(asnumbers$currentstatus))

but then when I view mydataset, the numbers aren't what they should be, they've changed by 1 or 2. And I can't see consistency, like sometimes a 1 will become a 2 and sometimes it wont. I'm confused.

Any suggestions?

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
Dizzy Bean
  • 411
  • 1
  • 4
  • 5
  • 1
    difficult to help without a reproducible example – h.l.m Jun 07 '13 at 15:22
  • 7
    Welcome to SO. Please have a look at http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. Your question would be easier to answer if you'd show also some example data. What is the output of `class(asnumbers$currentstatus)`? If it's a `factor` you have to call as.numeric(as.character(asnumbers$currentstatus))). You could also directly avoid the creation of factors when casting the vector prior to constructing the `data.frame` with `as.numeric` or construct the `data.frame` with `stringsAsFactors = FALSE`. See `? data.frame`. – Beasterfield Jun 07 '13 at 15:23
  • Eeeee! Thank you that seems to have fixed the problem. And thankyou for helping me despite the rudeness of no example data. I wasn't trying to be awkward its just a very big dataset and I assumed the summary was enough... – Dizzy Bean Jun 07 '13 at 15:53

0 Answers0