[R] colMeans function

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Wed Nov 4 14:37:00 CET 2020


On 04/11/2020 8:26 a.m., Engin Yılmaz wrote:
> 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

No, flights[2] is a dataframe with one column.  flights[[2]] would be 
the month column.

Duncan Murdoch



More information about the R-help mailing list