I am trying to achieve something like this, preferably in tidyverse way:
If(column1 == TRUE) {
column2 <- somevalue
column3 <- somevalue
column4 <- somevalue
}
Example data:
data <- tibble(
price = c(150, 35, 200),
price_type = NA,
price_currency = NA
)
I want to alter price_type and price_currency columns, depending on the result of test on price column.
I tryed several ways, nothing worked for me:
data %>%
rowwise() %>%
if(data$price == 1) {
data$price_type <- NA
data$price_currency <- "USD"
}
Nor this worked:
testfun <- function() {
if(price == 1){
price_type <- NA
price_currency <- "USD"
}
}
data %>% purrrlyr::by_row(testfun)
Many thanks in advance for any help