timothy.s.lau
timothy.s.lau

Reputation: 1101

How to apply a logic test to multiple vectors

I have a data frame with logical vectors and numeric. I was working on a solution to count the number of logical vectors when for some reason the is.logical function didn't working for me when applied to vectors. Any suggestions/alternatives?

apply(X = df1, MARGIN = 2, FUN = is.logical)

Upvotes: 1

Views: 207

Answers (1)

Sven Hohenstein
Sven Hohenstein

Reputation: 81693

If your data frame contains numeric columns too, you should not use apply for this task since the data frame is converted to a numeric matrix. Hence, no column is numeric. You can use sapply instead.

sapply(df1, is.logical)

Upvotes: 3

Related Questions