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.

Était-ce utile?

La 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)))
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top