0

I would like to summarize a dataframe ignoring the case. Because a column of my data frame was read in as a factor I first convert this column into a numeric. Doing this, the numbers somehow get mixed up.

My code:

    aggregated = as.data.frame(sapply(data, tolower))
    aggregated

returns

   hashtags   Freq   Company
#33contest   2   @Company1
#cebu   1   @Company1
#community   1   @Company1
#cost   1   @Company1
#countries   1   @Company1
#drug   1   @Company1

when I now convert column three into a numeric the results seem to be messed up

    aggregated$Freq <-as.numeric(aggregated$Freq)
    aggregated 

hashtags    Freq    Company
#33contest    9    @Company1
#cebu    1    @Company1
#community    1    @Company1
#cost    1    @Company1
#countries    1    @Company1
#drug    1    @Company1

What can I do about this?

Peter
  • 355
  • 1
  • 8
  • 23
  • Try `as.numeric(as.vector(aggregated$Freq))` – Veerendra Gadekar Jun 22 '15 at 16:21
  • Works perfectly. thx. For my understanding: Why do I need to convert this into a vector first? – Peter Jun 23 '15 at 07:40
  • you are getting inappropriate values for Freq because it is belongs to `factor class` and and if you will do `as.numeric` to a `factor` you will get internal codes and not the appropriate value. So you either need to convert the class into `character` or `vector` to get the appropriate values. Also have a look at the link indicated as duplicate question. – Veerendra Gadekar Jun 23 '15 at 09:20

0 Answers0