How can I get rid of NA values on data import in R? -


follow post:

http://r.789695.n4.nabble.com/importing-csv-gets-me-all-16-000-columns-with-quot-na-quot-td3006480.html

some background: developing program allows user upload csv files. currently, testing dataset looks like:

type    date    lively  count sm  1/13/2010   10  10 sm  1/14/2010   10  20 sm  2/15/2010   20  30  4/16/2010   5   42  1/17/2010   10  34  3/18/2010   40  54 sm  1/19/2010   10  65 sm  4/20/2010   5   67 sm  3/21/2010   40  76 sm  3/21/2010   70  76 

when user imports this, fine. import method is:

dataset <- read.csv(input$file$datapath) dataset <- na.omit(dataset) 

however, let's user saved above table in excel, saving csv. deleted last 2 columns.

type    date     sm  1/13/2010    sm  1/14/2010        sm  2/15/2010     4/16/2010     1/17/2010     3/18/2010    sm  1/19/2010    sm  4/20/2010    sm  3/21/2010    sm  3/21/2010    

if looked @ str() of table, last 2 columns wold contain na values because in excel, columns have been formatted. can't take in these na values, mess program later on. i'd rid of them. na.omit() doesn't seem nas.

i have found solution using

dataset[is.na(dataset)] <- c("") 

to replace these columns blank chars, mess me later when i'm checking columns of uploaded dataset characters!

does have better solution (telling user upload file in excel sheet not option )?

to remove columns containing na:

dataset [,colsums(is.na(dataset )) <nrow(dataset),drop=false] 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -