Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to include NA frequencies when making a list of frequency tables?

I have the dataframes df, df1, and the list l1 as follows :

df = data.frame(x = c(1,0,0,0,1,1,1,NA), y = c(2,2,2,2,3,3,2,NA),
                z = c(1:7,NA), m = c(1,2,3,1,2,3,1,NA) )

df$x = factor(df$x)
df$y = factor(df$y)
df$m = factor(df$m)

df1 = df%>%select_if(is.factor)

l1 = lapply(df1,table(useNA = 'always'))

when trying to include the useNA argument in l1 list, it doesn’t work. However, when applying the argument for each variable like for example table(df1$x,useNA = 'always'), it works properly. Would appreciate the help to handle this error.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The proper format for lapply is "lapply(X, FUN, …)" where the … are for the optional arguments for the function.

So in this case the argument: useNA = 'always' becomes:

lapply(df1, table, useNA = 'always')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading