Clean a set of data using R

0 votes

This is my dataset that is to be cleaned

NCM <- c(5,1,3,2,4)
Mbrand <- c(1,5,3,4,2)
data <- data.frame(NCM,Mbrand)

data$Mbrand <- factor(data$Mbrand, levels = c(1,5,3,4,2),
   labels = c("Brand1", "Brand5", "Brand3", "Brand4", "Brand2")) 

Expected output:

NCM Mbrand

5   Brand1

1   

3   Brand3

2   

4   Brand2

How do I go about this?

Nov 13, 2018 in Data Analytics by Ali
• 11,360 points
722 views

1 answer to this question.

0 votes

Try this:

NCM <- c(5,1,3,2,4)
Mbrand <- c(1,5,3,4,2)
fac<-factor(Mbrand, levels = c(1,5,3,4,2,''),
            labels = c("Brand1", "Brand5", "Brand3", "Brand4", "Brand2", '')) 


data<-data.frame(NCM, Mbrand=ifelse(NCM>=3, fac, ''))
answered Nov 13, 2018 by Maverick
• 10,840 points

Related Questions In Data Analytics

+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,872 views
0 votes
2 answers

How can I group a set of values by column using R programming?

Try this , Employee %>% group_by(EmpID) %>% mutate(SumSalary ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
836 views
0 votes
1 answer

Building Random Forest on a data-set comprising of missing(NA) values

You have two options, either impute the ...READ MORE

answered Apr 3, 2018 in Data Analytics by Bharani
• 4,660 points
1,431 views
0 votes
1 answer
0 votes
1 answer

Look for certain values from not cleaned data

First see what rows meet t$ps04==1 & t$rectyp==1. ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,840 points
667 views
0 votes
1 answer

Cleaning a Data Frame Using Regexp in R

The simplest way: library(dplyr) library(stringi) df %>% mutate(NUMERO_APPEL.fix = ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,840 points
806 views
0 votes
1 answer

How do I remove unnecessary redundant data from a dataset?

You can use dimensionality reduction methods such ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,840 points
1,627 views
0 votes
1 answer

Manipulate character string using gsub() and perform multivariate data cleaning efficiently in R

gsubfn is perfect for this task: library(gsubfn) as.vector(sapply(gsubfn("[A-Z]", list(B="* 1", ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,840 points
874 views
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
845 views
0 votes
1 answer

Replace comma with a period in data cleaning using R

You can use the scan function in ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,840 points
3,899 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP