I'm dealing with some RNA-seq count data for which I have ~60,000 columns containing gene names and 24 rows containing sample names. When I did some gene name conversions I was left with a bunch of columns that are named NA
. I know that R handles NA
differently than a typical column name and my question is how do I remove these columns. Here is an example of my data.
"Gene1" "Gene2" "Gene3" NA "Gene4"
1 10 11 12 10 15
2 13 12 50 40 30
3 34 23 23 21 22
I would like it to end up like
"Gene1" "Gene2" "Gene3" "Gene4"
1 10 11 12 15
2 13 12 50 30
3 34 23 23 22
I did identify some R code that worked for others but not for me
df<-df[, grep("^(NA)", names(df), value = TRUE, invert = TRUE)]
Looks like you have an actual
NA
in your names, instead of"NA"
. The former represents a missing value, the latter is a character string that looks like the symbol that represents the missing value. Use:Illustrating with
iris
: