-1

enter image description herehow do i remove the na's from the final out with out deleting the whole row

library(dplyr)
library(plyr)
library(tidyverse)
library(readxl)
library(ggplot2)
library(datasets)
library(formattable)
library(flextable)
library(xlsx)
file.list <- list.files(pattern='*.xlsx',recursive = TRUE)
file_names<-sapply(file.list,read_excel,simplify = FALSE)
df1<-rbind.fill(file_names)
vf1<- select(df1,"Location Address",City,State,ZIP,address1,address2,city,state,zip)
df1<-unite(vf1,'Full Address',"Location Address",City,State,ZIP,address1,address2,city,state,zip,sep = ",")
newdata<-na.omit(df1)
write.csv(newdata,"adv134.csv",row.names =FALSE)
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's unclear what your data looks like. How do you want to represent missing values in the output? Just zero-length strings? Are all those packages really essential for this particular question? – MrFlick Mar 02 '20 at 17:20
  • Given that the data is organized as row/column what is your expected output here? You either remove the row or column with NA's or you replace the NA's with a value that acts as no data. Perhaps your question is "how do I replace NA's"? There are numerous posts regarding this exact issue but in short you can replace NA's in a data.frame using: `x[is.na(x)] <- -99` as one of many approaches. In the future please provide a reproducible example without all of the excess packages and irrelevant code. – Jeffrey Evans Mar 02 '20 at 18:35
  • i added the output. and i want to place the na's with a blank – Roberto Flores Mar 02 '20 at 18:53

2 Answers2

2

Without data I can't test this, but it's likely that tidyr::replace_na could solve your issue.

TTS
  • 1,818
  • 7
  • 16
0

Using base r

newdata <- df1
newdata[is.na(new_data)] <- ""
Mr.Rlover
  • 2,523
  • 3
  • 14
  • 32