Vaibhav Singh
Vaibhav Singh

Reputation: 1209

Summarise across, nrow doesn't return anything

Why does below return output as data frame with 0 columns and 1 row, I have no idea what it means either.

The code ran is

iris %>% summarise(across(everything(),nrow)) 

Note that both of the below returns an output as expected

iris %>% summarise(across(everything(),length))
iris %>% summarise(across(everything(),mean))

Ideal Output received

Sepal.Length Sepal.Width Petal.Length Petal.Width Species
     150         150          150         150     150

Upvotes: 0

Views: 150

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 388982

nrow is used on dataframes, across does not pass data as dataframe it passes it as vector on which nrow does not work. For example,

nrow(1:10)
#NULL

You can use functions like length, NROW which works on vector to use in across.

Upvotes: 7

Related Questions