asathe1
asathe1

Reputation: 31

How do I create subset dataframe if column names are in the character list?

I have a data frame with a range of dates as the column names and a list of stock tickers down the y axis. I then have a separate character list of dates.

I want to create a subset of the data frame if the dates in the data frame match any of the dates in the character list.

Below please find links to images of the data frame and the list of dates. I would appreciate any advice as I have not been able to find a solution.

enter image description here

enter image description here

Upvotes: 0

Views: 186

Answers (1)

MBnnn
MBnnn

Reputation: 308

If understand you well, you want your data's column which are on the list you put ?

I think this could work :

new_data = data[,which(colnames(data)%in%your_list)]

Tell me if this isn't what you want.

Upvotes: 2

Related Questions