Remove NA in a Data Frame

Asked

Viewed 1,529 times

3

I import file containing more than 30 columns. A few blank rows that I imported the R recognizes as "NA". When exporting these same columns, the rows that should be blank (empty) appear with "NA". How do I export by swapping the "NA" for empty? I don’t want to delete the data, just that it appears empty.

2 answers

6


Assuming the dataset is called dados, turn the following command:

write.csv(dados, file="NomeDoArquivo.csv", na=" ", row.names=FALSE, quote=FALSE)

in which

  • na=" " says that all NA in dados shall be replaced by a blank

  • row.names=FALSE informs the R not to put the name of the lines in the final csv

  • quote=FALSE removes quotes from column names and categorical variables

5

In office write.table. write.csv and write.csv2, there is an option (na) where you define how you want the missing data to be exported.

Try write.table(x, ..., na = "")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.