[Solved] How to check multiple R columns for a value? [closed]


Something like this (assuming your data is named df)

# get the column names that follow this pattern
cols = grepl("[0-9]+_parameter", names(df))
# see if any of those columns have a 97
any(df[cols] == 97)

A base R way to filter for rows that have a 97 in any of those columns is this:

df[rowSums(df[cols] == 97) > 0, ]

1

solved How to check multiple R columns for a value? [closed]