# Making calculations based on specific values and names in columns

Hi,

Welcome to the RStudio community!

First of all, I'd like to point you towards our guide for creating a reprex so we can more easily use your data instead of sharing a screenshot. A reprex consists of the minimal code and data needed to recreate the issue/question you're having. You can find instructions how to build and share one here:

I recreated your dataset (some number are not the same in the rating) and used the dplyr package from the Tidyverse to create your results

``````library(dplyr)

#Get the data
myData = data.frame(
subjectID = "0532",
interpretationType = c("LureN", "LureE", "Absurd", "True"),
statementID = rep(1:3, 4),
rating = 0.5
)
myData
#>    subjectID interpretationType statementID rating
#> 1       0532              LureN           1    0.5
#> 2       0532              LureE           2    0.5
#> 3       0532             Absurd           3    0.5
#> 4       0532               True           1    0.5
#> 5       0532              LureN           2    0.5
#> 6       0532              LureE           3    0.5
#> 7       0532             Absurd           1    0.5
#> 8       0532               True           2    0.5
#> 9       0532              LureN           3    0.5
#> 10      0532              LureE           1    0.5
#> 11      0532             Absurd           2    0.5
#> 12      0532               True           3    0.5

#Filter the data only to have the variables of interest
myData = myData %>%
filter(statementID == 3 | interpretationType == "Absurd",
interpretationType != "True")
myData
#>   subjectID interpretationType statementID rating
#> 1      0532             Absurd           3    0.5
#> 2      0532              LureE           3    0.5
#> 3      0532             Absurd           1    0.5
#> 4      0532              LureN           3    0.5
#> 5      0532             Absurd           2    0.5

#Group the result by subjectID and calculate the sum
myData %>% group_by(subjectID) %>%
summarise(sumRatings = sum(rating), .groups = "drop")
#> # A tibble: 1 x 2
#>   subjectID sumRatings
#> * <chr>          <dbl>
#> 1 0532             2.5
``````

Created on 2021-01-26 by the reprex package (v0.3.0)

If you don't know the Tidyverse yet, you can check out the basics of dplyr here. It's really handy once you get to know it!

Hope this helps,
PJ