I've seen several threads on solutions to this, but I am struggling implementing them. I have a df with columns across the top with descriptions, and then I have a list of samples with data that are grouped by description. I need to extract the values where the descriptions match the column names.
I have tried different solutions using match, cbind, sapply...etc, but get errors about an invalid type(matrix) or having duplicate row names.
df1
#row description sample ball square circle
1 ball 1a .78 .04 .22
2 ball 7b3 .32 .33 .33
3 square aaabc .02 .90 .05
4 circle ggg3 .05 .04 .90
5 circle 44 .01 .25 .70
My output would be:
df2
#row description sample value
1 ball 1a .78
2 ball 7b3 .32
3 square aaabc .90
4 circle ggg3 .90
5 circle 44 .70
And then taking that one step further, I would then filter it
df2 %>%
filter(value < .9) %>%
select(description, sample, value)
Resulting in:
#row description sample value
1 ball 1a .78
2 ball 7b3 .32
3 circle 44 .70
I know this is a duplicate, I'm just drawing a blank as to why I can't get the solutions to work with this data set.