I have two lists that I'm getting from an API. I need to compare the two lists in R to determine which items are present in both lists. I had hoped to do this with the intersect() command, but it did not work. Upon further inspection, I noticed that each list was actually a single vector comprising multiple items separated by commas and escape characters. Is it possible to transform these vectors into multi-item lists so that I can compare lists? Here is some example code:
What I'd like:
> intersect(x,y)
[[1]]
[1] "c"
What I'm seeing instead:
> intersect(x,y)
list()
> as.character(x)
c(\"a\", \"b\", \"c\")
> as.character(x)
c(\"c\", \"d\", \"e\")
What's going on here? How do I compare x and y? Is there a way to transform these vectors into lists so that I can use the intersect() command?
edit: refined example and clarified data source