0

I have a list containing three different length of vectors with unique elements for each vector.

data <- list(ARG=letters[1:8],BRZ=c("a","b","c","f","h","g","l","m","n"),US=c("u","b","c","e","h","f","q","a","n","t"))

I would like to convert this list to a data frame by mergering them together, the result is expected as below or similar output, Thank you for helping this.

    ID  ARG BRZ US
    a   1   1   1
    b   1   1   1
    c   1   1   1
    d   1       
    e   1       1
    f   1   1   1
    g   1   1   
    h   1   1   1
    l       1   
    m       1   
    n       1   1
    q           1
    t           1
    u           1
2
  • You need library(qdapTools);t(mtabulate(data)) Commented Nov 30, 2017 at 16:12
  • 1
    @akrun perfect. Thank you so much! Commented Nov 30, 2017 at 16:14

1 Answer 1

2

We use mtabulate and transpose the output

library(qdapTools)
t(mtabulate(data))

Or if we are using base R, then stack into a data.frame with 2 columns and apply the table

table(stack(data))

Assuming that there are no duplicates for each entry. If there are duplicates, then we may need a logical vector coerced to binary

+(table(stack(data)) >0)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.