Say, I have a dataframe with three columns:

```
Year     Sales     Income
1         100       30
2         200       20
3         NA        10
4         300       50
5         NA       -20

```

I want to get all the 'Year' that has a particular value in 'Sales', ignoring other columns. For example, if I ask for NA, I should get:

```
Year    Sales
3       NA
5       NA

```

Please note there is no Income in the above data frame.
['https://Stackoverflow.com/questions/63925843', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13434461/']
We can use `base R` with `subset`

```
subset(df, is.na(Sales), select = c('Year', 'Sales'))
#  Year Sales
#3    3    NA
#5    5    NA

```

### data

```
df <-structure(list(Year = 1:5, Sales = c(100L, 200L, NA, 300L, NA
), Income = c(30L, 20L, 10L, 50L, -20L)), class = "data.frame", 
 row.names = c(NA, -5L))

```
you can use the %in% subsetting which has to be declared before. I usually use these in ggplot directly. hope they work independently too. For example:

```
col11 <- c("c11", "c12")
typecol2 <- c("c22", "c24")
data_new <- subset(data old, (col1 %in% col11) & (col2 %in% typecol2))

```