How can I remove NA strings in a simple data frame like the one below, which consists of a single column, in R?
head(test)
Column1
[1] "Gene1 Gene2 Gene3 NA NA NA NA"
[2] "Gene41 NAGene218 GeneX NA"
[3] "Gene19 GeneNA NA NA NA NA NA"
Some genes start or end with 'NA', so to avoid getting rid of those NAs, the gsub regex has to specify the position of the NA in the string... Something like:
test2 <- gsub('^ NA$', "", test$Column1), with ^ indicating that ' NA' has to be at the start and $ at the end of the string... I am sure it's something simple, but I don't understand what I am doing wrong? (As I am not very familiar with these regex symbols)
[UPDATE] - Desired output
head(test2)
Column1
[1] "Gene1 Gene2 Gene3"
[2] "Gene41 NAGene218 GeneX"
[3] "Gene19 GeneNA"