despite there being a column "Region" it is showing "object Region not found" ?

despite there being a column "Region" it is showing "object Region not found" ?

superstore_sales %>% Region <- filter(Region == Atlantic)

That line does not make sense to me. You are both passing the object superstore_sales to a function named Region and you are assigning the output of filter() (using bad syntax) to Region. Do you mean something like

AtlanitcDF <- superstore_sales %> filter(Region == Atlantic)
2 Likes

This is the error being shown :

Backtrace:

  1. ├─superstore_sales %>% filter(Region == Atlantic)
  2. ├─dplyr::filter(., Region == Atlantic)
  3. └─dplyr:::filter.data.frame(., Region == Atlantic)
  4. └─dplyr:::filter_rows(.data, dots, by)
  5. └─dplyr:::filter_eval(...)
    
  6.   ├─base::withCallingHandlers(...)
    
  7.   └─mask$eval_all_filter(dots, env_filter)
    
  8.     └─dplyr (local) eval()
    

Was missing the inverted commas. got it, thank you!

Got it.

Another question - How to get the top 10 highest numerics from a column ?

This code pulls the rows with the 5 highest values in the Value column. Is that similar to what you want to do?

DF <- data.frame(Name = LETTERS[1:10], Value = rnorm(10))
DF
#>    Name      Value
#> 1     A  0.1136478
#> 2     B -0.5487994
#> 3     C  0.3290922
#> 4     D -1.4037170
#> 5     E -2.2890380
#> 6     F -0.6978811
#> 7     G -0.6084363
#> 8     H -0.1210042
#> 9     I -0.1895910
#> 10    J -1.9519956
library(dplyr)

DF |> arrange(desc(Value)) |> slice(1:5)
#>   Name      Value
#> 1    C  0.3290922
#> 2    A  0.1136478
#> 3    H -0.1210042
#> 4    I -0.1895910
#> 5    B -0.5487994

Created on 2023-05-05 with reprex v2.0.2

1 Like

How could i filter the "top 10" profit numbers from different regions ?

Top 10 from - Atlantic
Top 10 from - Praire
Top 10 from - Quebec
etc...

super_store <- Id, profit , sales, region, discount, quantity, price

Top 10 values per region as follows. I don't know what value you're trying to get the top 10 of so I left it as 'value' below. Also note that you might get more than 10 if there are ties!

superstore_sales %>%
 group_by(Region) %>%
 slice_max(order_by = value, n = 10)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.