How to sum a column with a condition

Hello, I am very new in programming, I can't do one thing, I'll need help.
I have a database of 1500 observations, I want to know the productivity of women, I have two variables, sex and productivity, I wish to sum the productivity of women only for the all 1500 obs


Thank you !

Hello & welcome to the site!

You will need to be more specific in formulating your question, as there are multiple approaches possible, depending on the format of your data and tools on your disposal.

Three I can think of

  • SQL = sum(productivity) from yer_database where sex = 'F';
  • base R = sum(subset(yer_database, sex == "F")$productivity)
  • dplyr = yer_database %>% filter(sex == "F") %>% summarise(sum(productivity))

Plus there are sure to be many variants of this...


Thank you so much it works ! I had put an image of the database but it doesn't appear i don't know why, sorry

1 Like

I am glad it does, as I was in a sort of a snarky mood when writing the post. Please accept my apologies :slight_smile:


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