I have the following dataframe
Type Ca K Mg
<chr> <dbl> <dbl> <dbl>
1 parasite 12889. 21919. 3512.
2 host 8825. 18178. 2640.
3 parasite 14776. 32136. 3535.
4 host 9087. 24764. 1812.
5 parasite 13951. 31275. 4256.
6 host 7336. 23079. 1834.
7 parasite 17962. 35683. 4261.
8 host 7798. 26001. 2573.
9 parasite 15268. 35946. 4676.
10 host 7513. 29635. 2711.
I'd like to make a new column in which I sum across rows for the Ca, K and Mg "total" I then want to express these totals as a ratio in another column.
however, when I try to use mutate, the fact that I won't have 10 rows ( I would only have 5 since I am using 2 to get the desired division) is making it cause problems
As an example, just summing K and Ca
Parasite<- Leaf.orig %>%
filter(Type == "parasite") %>%
select(colnames(Leaf.orig)) %>%
mutate(K_Ca = K + Ca)
Host<- Leaf.orig %>%
filter(Type == "host") %>%
select(colnames(Leaf.orig)) %>%
mutate(K_Ca = K+Ba)
Leaf.orig %>%
mutate(K_Ba = Parasite$K_Ca/Host$K_Ca)
does not work. I'm very new to dplyr and R in general, so any help is appreciated!