'Multiply a column based on a category of another column

I am trying to transform a value of one column based on a categorical value of another column. So if the size of a column catchable I need to multiply the Fingerling by 11.08 and similar for the other sizes.

Year Water Species Size LbsStocked
2018 Beaver RBT Catch 1845
2018 Beaver RBT Yrl 100
2019 Beaver RBT Fingerling 200
library(ggplot2)
require(readxl)
library(dplyr)
library(scales)

####BEAVER FISH STOCKED
BData<-read_excel("Stocking Numbers_ALL_2006-2020.xlsx",
                 sheet = "AllSystemsLBs")
BData <- aggregate(LbsStocked ~ Year + Water + Species + Size, data=BData, FUN=sum)
BData <- filter(BData, Water == "Beaver Tailwater")
BData <- BData %>%
 mutate(LbsStocked = case_when(Size == "Fingerling" ~ LbsStocked * 11.08,
                        Size == "Catchable"  ~ LbsStocked * 1.84,
                        Size == "Yrl" ~ LbsStocked * 3.55,
                        TRUE ~ LbsStocked))

The mutate (case_when) command I am using currently is only adding significant figures and not multiplying the LbsStocked.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source