2

I have the following sqldf:

library(sqldf)
B <- sqldf(
  " select *
   , CASE
      WHEN Length = '1 day' THEN 1
      WHEN Length = '2 days' THEN 2
      WHEN Length = '4- 8 weeks' THEN 42
      WHEN Length = '26+ weeks' THEN 180
  END as lengthI
  from A
"
)
summary(B)

I was expecting to get lengthI as numeric, but somehow I got it as character ("2", "1", )

My questions are: 1. Why sqldf did not generate numeric var as expected? 2. Is there a way I can force type of lengthI with sqldf?

Thanks a lot.

AdamNYC
  • 19,887
  • 29
  • 98
  • 154
  • can you give me a sample of your A object, I can't reproduce the behavior with iris sample – agstudy Nov 23 '12 at 02:16
  • Hi agstudy. I tried to create sample and realized that my Length variable was factor and not character when I read in my file. Thanks for your help. – AdamNYC Nov 23 '12 at 16:43

0 Answers0