I have a data frame as follows:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] A 4 NA NA 1.55 4 NA
[2,] B NA NA 4 0.56 NA NA
[3,] C 4 4 NA 0.62 4 4
[4,] D NA NA NA 1.61 4 NA
[5,] E 4 NA NA 0.5 4 NA
What I would like to get as the output after filtering is:
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[3,] C 4 4 NA 0.62 4 4
[5,] E 4 NA NA 0.5 4 NA
I would like to have at least one value equals to 4 in columns 2 to 4 & at least one value equals to 4 in columns 6 to 7.
I was thinking to use the following command But I am not sure how to use it in a proper way that gives me the correct output.
here is the command:
new.df <- df %>%
dplyr::filter_at((vars(c(2:4)), any_vars(. == 4) & vars(c(6:7)), any_vars(. == 4))
Do you have any idea how can I get the desired new.df? Thanks!