Dear experts of R
I am really struggling against all the packages (purrr, tidyverse (summarise, mutate..))
It is impossible to me to write a code to perform iterative analysis, and I posted more than one post but nobody has known how to solve it more than the tidy part (at least with my database and map function/summarize). I've tried so much stuff that I am goint to reduce the actions
Let say I have "h"
tibble [1,683 x 51] (S3: tbl_df/tbl/data.frame)
$ paciente : num [1:1683] 6430 6430 6430 6494 6494 ...
..- attr(*, "format.spss")= chr "F5.0"
$ time : Factor w/ 3 levels "00","01","66": 1 3 2 1 3 2 1 3 2 1 ...
$ peso1 : num [1:1683] 115.4 110 114.5 76.2 73.6 ...
$ cintura1 : num [1:1683] 123 118 NA 106 104 ...
$ tasis2_e : num [1:1683] 139 147 NA 129 136 NA 136 138 NA 138 ...
$ tadias2_e : num [1:1683] 78 85 NA 63 71 NA 71 72 NA 76 ...
The object "h" has 3 levels of time (factor), with an ID (patient). The goal is compare values across time. The "h" object comes from
h <- BBDD_PPLUS %>%
select(paciente, matches("_v00|_v01|_v66")) %>%
pivot_longer(-paciente) %>%
separate(name, into=c("name", "time"), sep="_v") %>%
pivot_wider(names_from= name, values_from=value)
I have tried with map function creating a function containing aov but several error came up, so I incline towards:
h %>%
+ dplyr::summarise(across(output = ~aov(.x ~ time), .cols = everything()))
It is not working at all, because when I perform
identical(h, k)
TRUE
I have also tried
BBDD_PPLUS %>%
select(paciente, matches("_v00|_v01|_v66")) %>%
pivot_longer(-paciente) %>%
separate(name, into=c("name", "time"), sep="_v") %>%
pivot_wider(names_from= name, values_from=value) %>%
group_by(time) %>% mutate(time = factor(time)) %>%
dplyr::filter(time == "00" | time == "01" | time == "66") %>%
as.data.frame() %>%
map(.x = ., .f = ~aov(.x ~ time))
Error in model.frame.default(formula = .x ~ time, drop.unused.levels = TRUE) : variable lengths differ (found for 'time')
BBDD_PPLUS %>%
select(paciente, matches("_v00|_v01|_v66")) %>%
pivot_longer(-paciente) %>%
separate(name, into=c("name", "time"), sep="_v") %>%
pivot_wider(names_from= name, values_from=value) %>%
group_by(time) %>% mutate(time = factor(time)) %>%
dplyr::filter(time == "00" | time == "01" | time == "66") %>%
as.data.frame() %>%
map(.x = is.numeric, .f = ~aov(.x ~ time))
Error: .x
must be a vector, not a primitive function