R - split data frame without removing NA values
问题 If I have a df: letter body_part a head b head c NA d NA e left_foot And I want to split it into 2 dfs... One with only body_part - "head" and the other with everything else. I.e. list <- split(df, df$body_part == 'head') Can I do that without dropping the NA rows? (I know I can do it if I fill the NAs with a string, but is there a way that avoids that step?) 回答1: From ?`%in%` : That ‘%in%’ never returns ‘NA’ makes it particularly useful in ‘if’ conditions. # just to show how the `==`