1

I'm reading ISLR and in the Carseats file, I use:

Price <- as.factor(Price)

to make the variable Price a Factor for experiment. However, when I put:

str(Carseats)

it still shows that Price is Num not Factor. Of course when I try:

class(Price)

it is Factor. So, how do I really change the data type? I.E., how to change the data type in the csv file as well?

Corey Fang
  • 11
  • 2
  • 3
    Because you didn't modify the data frame. `Carseats$Price <- factor(Carseats$Price)` – hrbrmstr Nov 10 '18 at 10:49
  • 3
    Have you used `attach(Carseats)`? if so, don't. It's a source for errors of the type you are getting. Don't use `attach()` at all. – Rui Barradas Nov 10 '18 at 10:54
  • 3
    Thanks guys! In this link I saw the issue, it's because of `attach()` as suggested by @RuiBarradas : [https://stackoverflow.com/questions/10067680/why-is-it-not-advisable-to-use-attach-in-r-and-what-should-i-use-instead]. – Corey Fang Nov 10 '18 at 11:02

0 Answers0