如果列名在字符列表中,如何创建子集数据帧?

时间:2021-01-08 14:57:26

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.

我有一个数据框,其中包含一系列日期作为列名称和一个沿y轴向下的股票代码列表。然后我有一个单独的日期字符列表。

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.

请在下面找到数据框图像和日期列表的链接。我很感激任何建议,因为我找不到解决方案。

如果列名在字符列表中,如何创建子集数据帧?

如果列名在字符列表中,如何创建子集数据帧?

1 个解决方案

#1


2  

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.

告诉我,这不是你想要的。

#1


2  

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.

告诉我,这不是你想要的。