Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the subset function in R to retain all records while filtering for non-NA values in a column based on a condition in another column.

For example, if you have a data frame called "df" with columns "col1" and "col2", and you want to keep all rows where "col1" is greater than 5 and "col2" is not NA, you can use the following code:

subset(df, col1 > 5 & !is.na(col2))

This code will filter the data frame to only include rows where "col1" is greater than 5 and "col2" is not NA. All other rows will be excluded.