Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"object 'day' not found r". But 'day' is a column name [closed]

Tags:

r

dplyr

I'm studying the main functions of dplyr package. When I type flights I have it:

year month   day dep_time sched_dep_time dep_delay
   <int> <int> <int>    <int>          <int>     <dbl>
1   2013     1     1      517            515         2
2   2013     1     1      533            529         4
3   2013     1     1      542            540         2
4   2013     1     1      544            545        -1
5   2013     1     1      554            600        -6
6   2013     1     1      554            558        -4
7   2013     1     1      555            600        -5
8   2013     1     1      557            600        -3
9   2013     1     1      557            600        -3
10  2013     1     1      558            600        -2

we can see day is a column name. When I type:

jan1 <- filter (flights, month == 1, day==1)

I get the error message

Error in match.arg(method) : object 'day' not found

But it is a column name. Could you help me?

like image 337
Rafael Cancella Morais Avatar asked Apr 26 '17 11:04

Rafael Cancella Morais


2 Answers

i think you may have a different package loaded that also defines filter because

 library(nycflights13)
 filter(flights, month==1, day==2)

works for me.

Can you explicitly use dplyr::filter and see if it works then ?

dplyr::filter(flights, month==1, day==2)
like image 128
Janna Maas Avatar answered Sep 20 '22 06:09

Janna Maas


Try this:

library(dplyr)

df <- tbl_df(data.frame(year = sample(2000:2017,10,replace = T),month = sample(1:12,10,replace = T),day = sample(1:31,10,replace = T)))

may3 <- filter(df,month == 5) %>% filter(day == 3)

or

may3 <- filter(df,month == 5 & day == 3)
like image 23
Val Avatar answered Sep 19 '22 06:09

Val