質問

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