Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

type conversion - How to convert integer into categorical data in R?

My data set has 8 variables and one of them is categorical but R thinks that it is integer (0's and 1's). What I have to do inorder to covert it into categorical?

> str(mydata)
'data.frame':   117 obs. of  8 variables:
 $ PRICE: int  2050 2080 2150 2150 1999 1900 1800 1560 1450 1449 ...
 $ SQFT : int  2650 2600 2664 2921 2580 2580 2774 1920 2150 1710 ...
 $ AGE  : int  13 NA 6 3 4 4 2 1 NA 1 ...
 $ FEATS: int  7 4 5 6 4 4 4 5 4 3 ...
 $ NE   : int  1 1 1 1 1 1 1 1 1 1 ...
 $ CUST : int  1 1 1 1 1 0 0 1 0 1 ...
 $ COR  : int  0 0 0 0 0 0 0 0 0 0 ...
 $ TAX  : int  1639 1088 1193 1635 1732 1534 1765 1161 NA 1010 ...

COR should have been categorical.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have a look at ?as.factor. In your case

mydata$COR <- as.factor(mydata$COR)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...