Trying to remove this row and cannot get it. I have tried the multiple Q&A's on SO already and nothing seems to work. Tried using the sjmisc
library as someone suggested but it is still there. Here is what I have tried below and a snip of the df
.
EDIT:
Here is a DataFrame below to test. Removed a Pic of the dataframe which was incorrect and not proper policy.
df<-data.frame(name=c('CAREY.PRICE',NA,'JOHN.SMITH'),GA=c(3,2,2),SV=c(2,2,NA),stringsAsFactors = FALSE)
Which will return:
name | GA | SV
CAREY.PRICE| 3 | 2
NA | 2 | 2
John.Smith | 2 | NA
The issue with the below response:
df = df[complete.cases(df),]
It answers the question above technically, If a Column in any row has NA, remove it. I should have clarified that I would have like it to be a column of my choice which would have been the NA
in df$name
.
What this will do is remove NA
and John.Smith
. Which has caused an issue with my script and the lack of name
(players) in my DF.
I also had na.omit()
in my script and it removed NA
and John.Smith as well.
There are 40 variables in my DF and to write out each possible one that may or may not have an NA in it would be too much. My temporary solution is to change all NA's to 0:
df[is.na(df)] <- 0
RETURNS:
name | GA | SV
CAREY.PRICE| 3 | 2
0 | 2 | 2
John.Smith | 2 | 0
Then remove any df$name
that is 0:
df<-df[!(df$name==0),]
What I was looking for:
name | GA | SV
CAREY.PRICE| 3 | 2
John.Smith | 2 | 0