Skip to content

Instantly share code, notes, and snippets.

@markdly
Created May 10, 2018 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markdly/1f3c132766b89de16a6fe1f9012eb9aa to your computer and use it in GitHub Desktop.
Save markdly/1f3c132766b89de16a6fe1f9012eb9aa to your computer and use it in GitHub Desktop.
library(tidyverse)
library(conquestr)
df <- cq_example(display = FALSE) %>% cq_itanal() %>%
  select(-data)

df1 <- df %>% select(item_index:delta)
df2 <- df %>% 
  mutate(resp_id = id) %>%
  select(item_index, resp_id, resp_stat) %>% 
  unnest() %>% 
  mutate(item_index = if_else(
    item_index == lag(item_index, default = "X"), NA_character_, item_index))

df_export <- right_join(df1, df2, by = "item_index")
df_export
#> # A tibble: 50 x 17
#>    item_index id       case  disc  thrsh  mnsq  delta resp_id  label score
#>    <chr>      <chr>   <dbl> <dbl>  <dbl> <dbl>  <dbl> <chr>    <chr> <dbl>
#>  1 1          item:1~  1475  0.4   -1.36  1.25  -1.36 item:1 ~ 1         0
#>  2 <NA>       <NA>       NA NA     NA    NA     NA    item:1 ~ 2         0
#>  3 <NA>       <NA>       NA NA     NA    NA     NA    item:1 ~ 3         1
#>  4 <NA>       <NA>       NA NA     NA    NA     NA    item:1 ~ 4         0
#>  5 <NA>       <NA>       NA NA     NA    NA     NA    item:1 ~ 5         0
#>  6 <NA>       <NA>       NA NA     NA    NA     NA    item:1 ~ 9         0
#>  7 2          item:2~  1475  0.54  -1.95  0.89  -1.95 item:2 ~ 1         0
#>  8 <NA>       <NA>       NA NA     NA    NA     NA    item:2 ~ 2         0
#>  9 <NA>       <NA>       NA NA     NA    NA     NA    item:2 ~ 3         0
#> 10 <NA>       <NA>       NA NA     NA    NA     NA    item:2 ~ 4         1
#> # ... with 40 more rows, and 7 more variables: count <dbl>, pct_tot <dbl>,
#> #   pt_bis <dbl>, t <dbl>, p <dbl>, pv_avg <dbl>, pv_sd <dbl>

Created on 2018-05-10 by the reprex package (v0.2.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment