-1

I have got temperature data, which is stored as "factor", like this:

str(TEMPERATURE)
Factor w/ 2387 levels "-0.01","-0.02",..: 2285 2254 2256 2237 2217 2197 2175 
2162 2143 2143 ..

I use

TEMPERATURE<-as.numeric(TEMPERATURE)

Then, it becomes

str(TEMPERATURE)
num [1:39024] 2285 2254 2256 2237 2217 ...

I am wondering how to let it show real temperature, rather which levels the data belong to. Thanks.

Jeannie
  • 131
  • 1
  • 7

1 Answers1

1

Factors are stored internally as integers - specifically, indices in a lookup table. as.numeric extracts these integers, which is one of the amusing little quirks of R - this is almost never what someone will intend to do.

Convert first to character, then to numeric:

as.numeric(as.character(TEMPERATURE))
Stephan Kolassa
  • 7,953
  • 2
  • 28
  • 48