Replace multiple values in one cell

Timo V

I want to replace all the long names with codes. Some cells have 20 or more of that long names and i prefer the codes.

I have two dataframes:

Result

Number   Omschrijving  functie
102040   Kadaster      Grondwerker Landmeter
104510   Graven sleuf  Stratenmaker Grondwerker Landmeter

Functiecode

functie        code
Stratenmaker   F1
Grondwerker    F3
Landmeter      F17

Expected output:

df

Number   Omschrijving  functie
102040   Kadaster      F3 F17
104510   Graven sleuf  F1 F3 F17

Because in the column functie there more than one strings, i don't know how to fix this.

I tried subset, rbind, cbind and merge but the output is not what I need .


Data:

Result <- read.table(text = "
Number,Omschrijving,functie
102040,Kadaster,Grondwerker Landmeter
104510,Graven sleuf,Stratenmaker Grondwerker Landmeter
", header = TRUE, sep = ",")

Functiecode <- read.table(text = "
functie        code
Stratenmaker   F1
Grondwerker    F3
Landmeter      F17
", header = TRUE)
zx8754

Split on space " ", then replace with lookup:

lookup <- setNames(Functiecode$code, Functiecode$functie)

Result$functie <- lapply(strsplit(Result$functie, " "), function(i){
  paste(lookup[ i ], collapse = " ")
})

Result
#   Number Omschrijving   functie
# 1 102040     Kadaster    F3 F17
# 2 104510 Graven sleuf F1 F3 F17

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Handling Multiple Values in One Cell to Export To CSV

Multiple values in one cell

Replace multiple strings in one column with other values

Write multiple values to one cell - VBA

Pandas - value_counts on multiple values in one cell

how to save multiple Cell array values in one .csv file

Replace one symbol in an expression with multiple values

How to select multiple values for one table "cell" MySQL

Count duplicate cell values as one if multiple criteria are met

How can I replace multiple values per cell with a mean per cell for multiple columns and rows in R

String search multiple values in one cell

Replace multiple values in cell in Pandas

How to split values from one cell to multiple cells using bash

Joining R dataframe on multiple separable (concatenated) values in one cell

combining multiple userform textbox values into one cell

VLOOKUP with multiple criteria returning values in one cell

Index and Match formula with multiple Lookup Values but for one cell

Multiple values in one cell from select query

Change how multiple values in one cell are displayed

Pandas Dataframe - multiple values inside one cell?

How to convert multiple columns to a list of key values in one cell - Pyspark?

Lookup multiple values from one cell

Using ARRAYFORMULA with Multiple cell values in to one

Separating multiple values within one cell into multiple cells

read a csv with multiple values in one cell

Pandas DataFrame - What is the correct way to operate with multiple values in one cell?

How can I replace in Excel multiple values in one cell with values in a column using a macro?

How to lookup multiple values based on multiple criteria in one cell?

Sorting/grouping when there are multiple values in one cell