In the following data:
library(stringr)
library(purrr)
entry <- c("P17-Nationalist Revolutionary Movement-Free Bolivia Movement (Movimiento Nacionalista Revolucionario [MNR] - Movimiento Bolivia Libre [MBL] [MNR-MBL])",
"P18-Socialist Party (Partido Socialista [PS])",
"P19-Liberty and Justice (Libertad y Justicia [LJ])",
"")
something <- c(1,2,3,4)
x <- str_match_all(entry, "(?<=\\[).+?(?=\\])") %>% map(drop)
Election_Parties <- tibble::tibble(x, something, entry)
I would like to replace the character(0)
value with the value from a different column like this:
setDT(Election_Parties)[identical(x, character(0)) ,x := entry]
This however gives me the error:
Error in `[.data.table`(setDT(Election_Parties), identical(Election_Parties[, :
LHS of := must be a symbol, or an atomic vector (column names or positions).
What am I doing wrong?
DESIRED OUTPUT:
library(stringr)
library(purrr)
entry <- c("P17-Nationalist Revolutionary Movement-Free Bolivia Movement (Movimiento Nacionalista Revolucionario [MNR] - Movimiento Bolivia Libre [MBL] [MNR-MBL])",
"P18-Socialist Party (Partido Socialista [PS])",
"P19-Liberty and Justice (Libertad y Justicia [LJ])",
"4")
something <- c(1,2,3,4)
x <- str_match_all(entry, "(?<=\\[).+?(?=\\])") %>% map(drop)
Election_Parties <- tibble::tibble(x, something, entry)