Need help formatting query pulling information from two variables

In this first line I am trying to pull out all observations that have 5228 and this works.
hlthc5228_df <- proddesc_df$MAJOR_CAT_CD == 5228
summary(hlthc5228_df)
Mode FALSE TRUE
logical 46955 515837

But, I would like to pull out the number of observations that have 5228 with the total number of quantity. So if the quantity was 6, then the total # of codes with 5228 is 6, or if Quantity is 1, then total number of codes with 5228 is 1.
Tried this:
hlthc5228_df <- proddesc_df$MAJOR_CAT_CD == 5228 proddesc_df$SLS_QTY >= '1'

What exactly are you trying to do in substantive terms?

At the moment I do not think you are doing what you think you are doing.

Try something like this:

dat1  <-  data.frame(xx = c('a', 'b', "c", 'd'), yy = c(1,2,1,4))

dat2  <-  subset(dat1, yy == 1)

You are saying two different things here.

One you want the number of products sold that have a product code of 5228.

Two I want to find out how many quantity sold of each product code.

Okay, if I have this correctly what you want is the number of items sold by product code.

Here is a toy example,

## create a toy data set.
dat1  <-  data.frame(xx = sample(letters[1:5], 100, replace = TRUE), yy = (sample(1:12, 100, replace = TRUE)))

## count the number of times the product code appears in the data

dat2  <-  dat1 %>%  group_by(xx)   %>% 
                summarize( n = n())
dat2

In the second line of code you want to replace dat1 with the name of your data.frame or tibble. Then replace xx with the name of the column of product codes and you should be fine.

Best wishes

This topic was automatically closed 21 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.

I will try that suggestion, Thank you.
Not sure if this helps:
I am trying to pull out the number of products sold that have a product code of 5228.
I have a column of product codes. I have a column of quantity sold.
I want to find out how many quantity sold of each product code.