R programming: Classifying wine dataset

+1 vote

The wine Data contains a feature called quality with numerical values in the range of 1 to 8. To categorize them, I tried the below code:

wineData$taste <- NA
wineData$taste[which(wineData$quality< 6)] <- bad
wineData$taste[which(wineData$quality>6)] <- excellent
wineData$taste[which(wineData$quality=6)] <- normal
wineData$taste <- factor(wineData$taste)
wineData`

With this code only the quality>6 is categorized as excellent and all others as NA. Why is it not able to categorize the others?

This is the error I'm getting:

wineData$taste[which(wineData$quality>6)] <- excellent Error: object 'excellent' not found wineData$taste[which(wineData$quality==6)] <- normal Error: object 'normal' not found
Feb 27, 2019 in Data Analytics by Tyrion anex
• 8,550 points
148 views

1 answer to this question.

0 votes

Run the below code, it should work:

wineData$taste <- NA
    wineData$taste[which(wineData$quality< 6)] <- "bad"
    wineData$taste[which(wineData$quality>6)] <- "excellent"
    wineData$taste[which(wineData$quality==6)] <- "normal"
    wineData$taste <- factor(wineData$taste)
    wineData
answered Feb 27, 2019 by Sophie may
• 10,100 points

Related Questions In Data Analytics

0 votes
1 answer

How to cluster a very large dataset in R?

You can initially use kmeans, to calculate ...READ MORE

answered Jun 19, 2018 in Data Analytics by Sahiti
• 6,320 points
773 views
0 votes
2 answers

What are the rules to define a variable name in R programming language?

The same rules almost follow for all ...READ MORE

answered Aug 26, 2019 in Data Analytics by anonymous
• 32,490 points
1,425 views
0 votes
1 answer

Why should I adopt R programming

R Programming is the best mechanism for ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,820 points
79 views
+3 votes
2 answers

Error: could not find function - R Programming

Yes, Just like @Maverik said, It happens ...READ MORE

answered Aug 22, 2019 in Data Analytics by anonymous
• 32,490 points
18,193 views
+1 vote
1 answer

R programming error

Alright, you can either use gsub to match the ...READ MORE

answered Dec 18, 2018 in Data Analytics by Tyrion anex
• 8,550 points
72 views
0 votes
1 answer

R Programming error in 'fert'

You're using a factor: fert <- factor(c(50,20,10,10,20,50)) levels(fert) #[1] ...READ MORE

answered Dec 27, 2018 in Data Analytics by Sophie may
• 10,100 points
101 views
+1 vote
1 answer

R Programming: Market Basket Analysis Error

The basket.sorted() has less than 5 rules. Refer ...READ MORE

answered Feb 11, 2019 in Data Analytics by Sophie may
• 10,100 points
430 views
+1 vote
1 answer

R Programming: regexpr error

The below code will help: gregexpr("D", x) # [[1]] # ...READ MORE

answered Feb 21, 2019 in Data Analytics by Tyrion anex
• 8,550 points
69 views
+1 vote
1 answer

R Programming: matrices

Try this, It will test if a matrix ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 10,100 points
64 views
0 votes
1 answer

R programming: Unexpected symbol error

Format your code this way: myfunction <- function() ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 10,100 points
1,219 views