I am not quite sure why this piece of code isn't working.
Here's how my data looks like:
head(test)
  Fiscal.Year Fiscal.Quarter   Seller Product.Revenue Product.Quantity Product.Family Sales.Level.1          Group Fiscal.Week
1        2015         2015Q3 ABCD1234            4000                4      Paper cup      Americas Paper Division          32
2        2014         2014Q1  DDH1234             300                5   Paper tissue  Asia Pacific Paper Division          33
3        2015         2015Q1  PNS1234             298                6         Spoons          EMEA        Cutlery          34
4        2016         2016Q4  CCC1234             289                7         Knives        Africa        Cutlery          33
Now, my objective is to summarize revenue by year.
Here's the dplyr code I wrote:
test %>% 
  group_by(Fiscal.Year) %>%
  select(Seller,Product.Family,Fiscal.Year) %>%
  summarise(Rev1 = sum(Product.Revenue)) %>%
  arrange(Fiscal.Year)
This doesnt work. I get the error:
Error: object 'Product.Revenue' not found
However, when I get rid of select statement, it works but then I don't get to see the output with Sellers, and Product family.
test %>% 
  group_by(Fiscal.Year) %>%
 # select(Seller,Product.Family,Fiscal.Year) %>%
  summarise(Rev1 = sum(Product.Revenue)) %>%
  arrange(Fiscal.Year)
The output is :
# A tibble: 3 x 2
  Fiscal.Year  Rev1
        <dbl> <dbl>
1        2014   300
2        2015  4298
3        2016   289
This works well.
Any idea what's going on? It's been about 3 weeks since I started programming in R. So, I'd appreciate your thoughts. I am following this guide: https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html
Also, I looked at similar threads on SO, but I believe they were relating to issues because of "+" sign:Error in dplyr group_by function, object not found
I am looking for the following output:
  Fiscal.Year  Rev1 Product Family Seller
        <dbl> <dbl> ...             ...
1        2014   ...
2        2015   ... 
3        2016   ...
Many thanks
 
    