Alvin Alvin - 5 months ago 31
R Question

How to count the number of column with the "TissueA" in a data frame

enter image description here

How to count the no. of column with the "TissueA" in the dataframe?
and also how to find the values of for eg. TCGA-A6-2676_TissueA,A2M|2

Thanks for your help


Try using

length(grep(".*_TissueA", names(dat)))

This will return the number of columns that end with _TissueA in your dataframe (dat).

If you want to know the specific indices of those columns (i.e., where they are in your dataframe), just use the 'grep' part:

grep(".*_TissueA", names(dat))

The return values will give the column indices (this output is just an example, it will be different for your dataframe):

[1] 62 63 89 94 95

In addition, if you want to actually see a dataframe with the values in those columns (and only those columns), try the following:

dat[,grepl(".*_TissueA", names(dat))