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
• 10,450 points
23 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,040 points

Related Questions In Data Analytics

0 votes
1 answer

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$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
80 views
0 votes
1 answer

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

Use the dplyr package that R provides: library(dplyr) df1 ...READ MORE

answered Apr 25 in Data Analytics by Sophie may
• 9,430 points
30 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 2, 2018 in Data Analytics by Bharani
• 4,550 points
96 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,040 points
20 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,040 points
19 views
0 votes
1 answer

How do I remove unnecessary redundant data from a dataset?

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

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,040 points
31 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,040 points
20 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,040 points
28 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,040 points
28 views