-3
I have a column in the dataset that has several variants of 5 options. I wanted to group based on what you have written in common. For example:
coluna1
lapis vermelho grande
lapis azul grande
lapis verde pequeno
lapis vermelho pequeno
I want to create a column, keeping the original, but group by character
coluna1 coluna2
lapis vermelho grande caixa grande
lapis azul grande caixa grande
lapis verde pequeno caixa pequeno
lapis vermelho pequeno caixa pequeno
thought of creating a WHEN, or if Else but I couldn’t get the logic to capture a word in the string. anyone with suggestion?
this resolution, have regex material to indicate? Thanks for the answer
– whatshallwedon0w
I can take this code and take words in different positions? and the code could identify a word? for example: I put 'red' and it calls everyone who has red regardless of position?
– whatshallwedon0w
@whatshallwedon0w No, this regular expression only finds the last word. To extract a word, for example 'red', you can do
stringr::str_extract(df$coluna1, 'vermelho')
.– Rui Barradas
@whatshallwedon0w Regarding regex material, see R base or package stringr.
– Rui Barradas