Вопрос

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.

Это было полезно?

Решение

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)))
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top