Hello,

No, flights[2] is *not* equal to flights$months. The former is a data.frame with only one column, therefore it has a dimension attribute. The latter is a column, a vector of the data.frame flights, it does not have the attribute dim set.

The difference is very important, see what class(), str() or dim() return when applied to both.

See also this StackOverflow post:

https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el


Hope this helps,

Rui Barradas

Às 13:26 de 04/11/20, Engin Yılmaz escreveu:
Dear
I use *flights* database library(nycflights13)

The following code is working as

colMeans(flights[2])

* 6.54851*

but other code is  not working as

colMeans(flights$month)

*Error in colMeans(flights$month) : *
*  'x' must be an array of at least two dimensions*

*flights[2]* is equal to the *month *column in database

*Sincerely*
Engin YILMAZ

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to