I have a meta data frame and a counts data frame. The counts data frame has samples IDs as column headers and has 477 columns. The meta data frame has the first column called samples that has sample IDs as its values in the rows. It has 465 values or rows. I am trying to keep only the samples in the counts file that occur in the samples column of the meta data frame. I have tried this command:
counts=counts[,meta$sample]
however, I get this error
Error in [.data.frame(counts, , meta$sample) : undefined columns selected Calls: [ -> [.data.frame
I need help on why I am getting that error when I use that command. I know this works because it worked previously on another data frame and even on a dummy data frame set that I created. So if someone could help explain why this command is not working. Do not require another solution to this just why this command is giving me that error. Appreciate the help
CodePudding user response:
The issue seems to be that meta$sample
may be a numeric/integer column and the column names in counts
is character
. When we use integer
columns, it will be column index i.e. looking for 246264
column instead of the column name "246264"
. Convert to character
and it should work
counts[, as.character(meta$sample)]