Один вариант будет expand.grid
из base R
(без использования каких-либо внешних пакетов)
df1 <- expand.grid(ID = v1, Condition = v2)
Или используя data.table
library(data.table)
CJ(ID = v1, Condition = v2)
# ID Condition
# 1: s009 Baseline
# 2: s009 Creativity
# 3: s009 Meditation
# 4: s009 Postblock 1
# 5: s009 Postblock 2
# ---
#332: s050 Postblock 1
#333: s050 Postblock 2
#334: s050 Practice
#335: s050 Preblock 1
#336: s050 Preblock 2
Или используя tidyverse
library(tidyverse)
tibble(ID = v1) %>%
expand(ID, Condition = v2)
# A tibble: 336 x 2
# ID Condition
# <chr> <chr>
# 1 s009 Baseline
# 2 s009 Creativity
# 3 s009 Meditation
# 4 s009 Postblock 1
# 5 s009 Postblock 2
# 6 s009 Practice
# 7 s009 Preblock 1
# 8 s009 Preblock 2
# 9 s010 Baseline
#10 s010 Creativity
# … with 326 more rows
, где
v1 <- sprintf("s%03d", 9:50)
v2 <- c("Baseline", "Meditation", "Practice", "Creativity",
"Preblock 1", "Postblock 1", "Preblock 2", "Postblock 2")