I have the following data frame:
STUDYID USUBJID IDVAR IDVARVAL
<chr> <chr> <chr> <chr>
1 study1 1 DSSEQ 3
2 study1 1 DSSTINV N
3 study1 1 DSDECOD1 SCREEN FAILURE
4 study1 2 DSSEQ 1
5 study1 2 DSDECOD2 ADVERSE EVENT
And I want to transpose it to the following format
STUDYID USUBJID DSSEQ DSSTINV DSDECOD1 DSDECOD2
1 study1 1 3 N SCREEN FAILURE
4 study1 2 1 ADVERSE EVENT
I used:
supp_ds <- dcast(suppdsT, STUDYID + USUBJID ~ IDVAR, value.var="IDVARVAL")
but it gave me something like:
STUDYID USUBJID DSDECOD1 DSDECOD2 DSDECOD3 DSDECOD4 DSDECOD7
1 study1 1 1 0 0 0 0
2 study2 2 0 0 0 0