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```

Nov 13, 2018 445 views

## 1 answer to this question.

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, ''))```
• 10,840 points

+1 vote

## 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

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

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

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

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

## How to use a function to repeat a set of procedures on specific set of columns in a data frame?

You can parse the strings to symbols. ...READ MORE

## Look for certain values from not cleaned data

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

## Cleaning a Data Frame Using Regexp in R

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

## How do I remove unnecessary redundant data from a dataset?

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

## 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