I'm python user learning R.
Frequently, I need to check if columns of a dataframe contain NaN(s).
In python, I can simply do
import pandas as pd
df = pd.DataFrame({'colA': [1, 2, None, 3],
'colB': ['A', 'B', 'C', 'D']})
df.isna().any()
giving me
colA True
colB False
dtype: bool
In R I'm struggling to find an easy solution. People refer to some apply-like methods but that seems overly complex for such a primitive task. The closest solution I've found is this:
library(tidyverse)
df = data.frame(colA = c(1, 2, NA, 3), colB = c('A', 'B', 'C', 'D'))
!complete.cases(t(df))
giving
[1] TRUE FALSE
That's OKyish but I don't see the column names. If the dataframe has 50 columns I don't know which one has NaNs.
Is there a better R solution?