在R中子集数据框:如何选择和子集包含以特定模式开头的值的列

我正在尝试对该数据框进行子集化(我只是展示其中的一部分):

                                              A1        A2        A3        A4
Treatment/ID                              WT 1um    WT 1um WT 0.5 uM WT 0.5 uM
    ISI Coefficient of Variation - Avg  5.585675  5.429892            5.105773
    Number of Active Electrodes               14        16                  16
    Weighted Mean Firing Rate (Hz)      1.512755  1.459375            1.738988
    Number of Bursting Electrodes             13        16                  16
    Number of Spikes per Burst - Avg   15.441462 13.902545           17.146523

In the end, I was asked to write many .csv files, each one containing the columns with the same value of concentration in the row Treatment/ID (for example, creating a .csv with all the columns of the dataframe containing 1uM as value of Treatment/ID; then another with 0.5uM, and so on).

I tried using grep and grepl, but I couldn't manage to extract the columns; it's evident that I cannot use them properly.

在此先感谢您的帮助!

评论