subset - R: Subsetting column 1 based on vector of values potentially present in column 2 -


i have dataframe kegglist, pertinent section of show below:

> kegglist[131:145,]         v1       v2 131 a0avt1 hsa04120 132 a0pjz3 hsa00514 133 a1a4s6 hsa05100 134 a1a4y4 hsa05145 135 a1l167 hsa04120 136 a2rtx5 hsa00970 137 a3kft3 hsa04740 138 a4d0s4 hsa05146 139 a4d0s4 hsa04512 140 a4d0s4 hsa04510 141 a4d0s4 hsa05200 142 a4d0s4 hsa05222 143 a4d0s4 hsa05145 144 a4d2g3 hsa04740 145 a5d8v6 hsa04144 

i have vector listx contains some, not all, of ids in v1 of kegglist:

> listx [1] a1l167 a2rtx5 a3kft3 a4d0s4 

what want subset kegglist$v2 based on ids in kegglist$v1 present in listx. so, in example, result should this:

> result  [1] hsa04120 hsa00970 hsa04740 hsa05146 hsa04512 hsa04510 hsa05200 hsa05222 hsa05145 

please note in real data, not ids in listx found consecutively in kegglist$v1. thank help.

i tried

result <- kegglist$v1[kegglist$v2 %in% listx] 

to no avail.

try: kegglist$v2[kegglist$v1 %in% listx]

or: kegglist$v2[which(kegglist$v1 %in% listx)]


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -