6

I am an R novice and am having some challenges. I am dealing with a large dataframe which I have read from a csv file. My numerical vectors contain NAs which are stopping me from running analyses. How do I get rid of these NAs so I can actually do something with my data?

Greg
  • 61
  • 1
  • 1
  • 2
  • 2
    Try the http://RSeek.org website for queries this. – Dirk Eddelbuettel Jun 29 '10 at 23:01
  • 3
    And before rseeking make sure you read [R Introduction](http://cran.r-project.org/doc/manuals/R-intro.html), [missing values](http://cran.r-project.org/doc/manuals/R-intro.html#Missing-values). – Marek Jun 30 '10 at 05:32

3 Answers3

8
  • for particular variable: x[!is.na(x)], or na.omit (see apropos("^na\\.") for all available na. functions),
  • within function, pass na.rm = TRUE as an argument e.g. sapply(dtf, sd, na.rm = TRUE),
  • set global NA action: options(na.action = "na.omit") which is set by default, but many functions don't rely on globally defined NA action (mean for instance), while some do (right now I cannot come up with an example),
  • and, of, course, if you have a lot of NA's, you should consider variable imputation, there's a question asked on SO that can be helpful.

Long story short, dealing with NA's is a very broad problem, try to concretize it a bit and give us a concise question. I'm sure that someone of SOers can help you!

Cheers, lad!

Community
  • 1
  • 1
aL3xa
  • 35,415
  • 18
  • 79
  • 112
5
na.omit(dataFrame)

This is an awesome website that I use for quick R related information: http://www.statmethods.net/input/missingdata.html

Dave
  • 417
  • 6
  • 15
0

It can be done by using na.omit() function.

myVec <- na.omit(myVec)
Pabitra Dash
  • 1,461
  • 2
  • 21
  • 28