I noticed that I get different results when subsetting using subset,
compared to subsetting using  "brackets" when the subset criteria have
NA's.

Here's an example

#START OF EXAMPLE
my_data <- 1:5
my_data

my_subset_criteria <- c( F, F, T, NA, NA)
my_subset_criteria

#subsetting using subset returns the data where my_subset_criteria equals TRUE
my_data[my_subset_criteria == T]

#subsetting using brackets returns the data where my_subset_criteria
equals TRUE, and also NA where my_subset_criteria is NA
subset(my_data, my_subset_criteria == T)

#END OF EXAMPLE

This behavior is also mentioned here
https://statisticaloddsandends.wordpress.com/2018/10/07/subsetting-in-the-presence-of-nas/

Q. Is this the intended behavior when subsetting with brackets?

Thank you!

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to