I have a table with ~8000 observations and 65 variables. I have another table with 35 observations ad 11 variables.
The larger table looks like this: portion of the larger table
and the smaller table looks like this: portion of the smaller table
As you can see, the first column of the smaller table contains some of the column names of the larger table. How can I, in a way more compact than simply writing out which columns I want to select, make R create a table that has the data in the larger table with only the columns specified in the smaller table?
Any help would be greatly appreciated!
UPDATE: Thank you to the answerer for the data. I was wondering if it would be possible to match the order of the columns in the large.df with the order the names appear in the small.df
large.df <- data.frame(A=rnorm(5), B=abs(rnorm(5, sd=0.08)),
C=rnorm(5), D=abs(rnorm(5, sd=0.08)))
A B C D
1 0.2367193 0.002297593 -0.1958682 0.03877595
2 -1.2419638 0.034031808 0.3253622 0.02578829
3 -0.2718915 0.188627689 0.4844783 0.04405741
4 -0.6587699 0.024045926 -1.1209473 0.09849541
5 1.7890422 0.055520325 0.1093612 0.11637796
samll.df <- data.frame(Category = c("B","D"))
samll.df
Category
1 D
2 B
I would like the output to have the columns ordered 'D', 'B', not 'B', 'D'. My example has ~35 columns so a way that is more compact than typing out the column names in the desired order would be ideal. Thank you