Hi Guys,
i´m a beginner in coding and use simple functions from the dplyr and tdyr packet. I generated the following tibble:
In the first column you see the calender week. In the second the option key 1,2,3 and 4. And in the third column yout see the frequency. Now i want to calculate 10 percent of option key 3 and substract that value from option key 3 and add that value to a third to option key 1,2 and 4. How can i best realize that? I tryed the following:
raw_disc <-
mutate(raw_count, Rabatt = Häufigkeit*0.1)
raw_part <-
mutate(raw_disc, Anteil = Rabatt/3)
raw_tastedrei <-
filter(raw_part, Tag == "taste 3")
raw_diff <-
mutate(raw_tastedrei, Anzahl = Häufigkeit - Anteil)
raw_add_tasteeins <-
filter(raw_part, Tag == "taste 1")
But now when i try to add up the value, in this case on option key 1, i get an error message.
mutate(raw_add_tasteeins, Anzahl = Häufigkeit + raw_add_tasteeins$Anteil)
Anzahl
must be size 1, not 11.
The error occurred in group 1: Kalenderwoche = 10.
Run rlang::last_error()
to see where the error occurred.
Who can help me with this error and show me a better way to calculate that? Thanks a lot!