I am a newbie to R. I have a list t1
in R which looks like
[[1]] [[1]][[1]] [1] "a" "control" [[2]] [[2]][[1]] [1] "a" "disease1" [[3]] [[3]][[1]] [1] "a" "disease2" [[4]] [[4]][[1]] [1] "b" "control" [[5]] [[5]][[1]] [1] "b" "disease1" [[6]] [[6]][[1]] [1] "b" "disease2"
I need to get a unique list of first elements into a vector i.e ["a", "b"] from this vector t1
. How can I do this?
rapply
offers yet another option:
unique(rapply(t1, function(x) head(x, 1)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With