Ask coding questions

← Back to all posts
How can I test a number of columns in a data.table for a specific value using R
SaiNikhilAchyut (0)

As you can see, I am having a test variable and on that, I am having a table taken this question from Data Science Certification:

test <- data.table(name = c("mike", "kate", "jeff"), ownership = c("1", "3", "4"), worth = c("1", "2", "3"), tax = c("4", "1", "4"))

I am trying to test if any rows (people) contain a row that contains "1".

I have tried the following but I want my syntax to be a bit more concise.

test <- test[ownership == "1" | worth == "1" | tax == "1", status := "yes"]