0
In R I want to make a new based on text with numbers. But I want to do this based on a specific part of the text.
For example when the text is like
- search | Location | Value
- search | Radius | Value
I want to make a new column with value 0 for every part of text which contains location.
I know that I can code this in columns with
ffclean$Campaign2[ffclean$Campaign=="Search | location| value"]<-0
But does somebody know how to code this when you only looking for the word location?
You might use str_detect
to detect a string or strsplit
to divide the three components into their own columns.
library(tidyverse)
str_detect(text, "Location")`
strsplit(text, " | ") %>% map(matrix, nrow = 1) %>% map_dfr(as_tibble, .name_repair = "unique")
1 Like
Thnx for your help!
This is not working for me.
Do you know if there is a function that says if the column Campaign contains "location" give value 0 in column campaigns2?
As a beginner to R you may benefit from studying this useful book.
https://r4ds.had.co.nz/
Particularly chapter 5
system
Closed
5
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.