Hi there: I would like to add a column to a dataframe that looks like this that has the number of missing values in it.
var1<-rnorm(100)
var2<-rnorm(100)
df<-data.frame(var1, var2)
#Set 1 missing value
df[1,1]<-NA
df[2,1]<-NA
library(tidyverse)
df
df %>%
#I know select is somewhat superflurous in this dataframe, but I need it in my example, so I want to be sure I get ti right
select(var1, var2) %>%
is.na() %>%
#The missing values are there.
head()
#How do I add the counts
df %>%
select(var1, var2) %>%
rowwise() %>%
mutate(na=rowSums(is.na(.)))