Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

how to write a nested if else statement in data.table r

$
0
0

Below is a general form of nested if-else statement using dplyr package. So I have two questions

  • What is the equivalent code using data.table the below form?
  • is there any other faster function to be replaced to str_detect() to speed up the below code?
# assuming we have two data frames x and y ;
x <- mutate(x, test =ifelse(x$A %in% y$A & x$B %in% y$C, "Number 1",
                     ifelse(str_detect(x$D,"TB"),        "exclude",                                                                            
                     ifelse(str_detect(x$D,"GL"),        "exclude",
                     ifelse(x$E %in% y$`B`,              "exclude", test))))))

my real code has 10 more ifesle in the above code line.


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>