Question

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.

Was it helpful?

Solution

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)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top