'Merge Tables from rerun purrr output in R
I'm sure it's pretty easy, but I'm fairly new to R and can't figure it out. What I want to do is create one table that binds all the tables together. The column order changes on every table, so I need to specify the variables names to be bound together. I just don't know how to merge all the individual tables from the output as one dataframe. Any other suggestions on how to get 4 conditions with 4 levels each randomised, that would be amazing!
This is the code so far
purrr::rerun(20, data.frame(
cry = sample(4, 1, replace = F),
laugh = sample(4, 1, replace = F),
babble = sample(4, 1, replace = F),
aversive = sample(4, 1, replace = F)
) %>%
sample(4)
)
Looking forward to any help!!
Thanks guys!
Solution 1:[1]
purrr::rerun(20, data.frame(
cry = sample(4, 1, replace = F),
laugh = sample(4, 1, replace = F),
babble = sample(4, 1, replace = F),
aversive = sample(4, 1, replace = F)
) %>%
sample(4)
) %>%
bind_rows()
laugh cry babble aversive
1 2 1 2 3
2 2 1 2 4
3 1 4 4 1
4 3 3 1 1
5 4 1 4 3
6 2 2 1 3
7 2 4 4 4
8 1 3 1 3
9 4 4 3 3
10 2 2 2 1
11 4 2 2 4
12 3 3 3 4
13 4 1 4 3
14 4 2 1 2
15 4 4 2 4
16 1 1 1 2
17 3 3 4 3
18 2 2 3 3
19 3 3 4 1
20 3 3 3 2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lennyy |
