Pregunta

I would like to apply a "composed" function on all columns of a data frame.

For the example, sum(is.na). But:

lapply(data, sum(is.na))

returns an error.

Of course, one "simple" function does work, such as

lapply(data, is.na)

So, how can we apply "functions of functions"?

In particular, the composed function I have in mind is

plot(table)

with as many graphics generated as there are columns in the data frame.

¿Fue útil?

Solución

Try this

apply(data, 2, function(x) sum(is.na(x)))
lapply(data, function(x) sum(is.na(x)))
sapply(data, function(x) sum(is.na(x)))
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top