I have a function from a package(tidycensus), that I want to use it through the piping and mutate. I have created this simple mockup to show the situation.
library(tidycensus)
tt <- as_data_frame(matrix(1:36, ncol = 6))
colnames(tt) <- c("A", "B", "C", "D", "E", "F")
tt2 <- tt %>% mutate(moe=moe_prop(.[,"A"],.[,"C"], .[,"D"],.[,"B"]))
The final result wraps the results into lists (all equal with the calculated values in each) and puts them in each place of moe column, as you can see below. Obviously, I want a vector as a result which fills column moe
> tt2
# A tibble: 6 x 7
A B C D E F moe
<int> <int> <int> <int> <int> <int> <list>
1 1 7 13 19 25 31 <dbl [6]>
2 2 8 14 20 26 32 <dbl [6]>
3 3 9 15 21 27 33 <dbl [6]>
4 4 10 16 22 28 34 <dbl [6]>
5 5 11 17 23 29 35 <dbl [6]>
6 6 12 18 24 30 36 <dbl [6]>
I know that using [,"Column_name]
format returns list. Therefore, I tried to add as.vector
beofore each of the input variables into the function. still same results. I wonder what I am missing here.