Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generating a subtable from a csv file based on another list

Tags:

r

csv

I have two CSV files. One stores a long list M such as

type  price
A      100
B      200
C      300
D      600
...

The other list N also stores a list which correlate with M in terms of "type". But the length of list N is smaller than M For instance, it just has

type   Performence
D      0.5
B      0.1

Is there a way to quickly find the subset of M which contains the type included in N. Within the context of the above example, I need the generate a sublist from M as

type  price
B      200
D      600
like image 582
bit-question Avatar asked Aug 03 '26 17:08

bit-question


1 Answers

Assuming you already have your files as datafames:

M.sub <- M[M$type %in% N$type,]
like image 183
alexwhan Avatar answered Aug 05 '26 15:08

alexwhan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!