我有一个简单的闪亮应用程序,可以从其中下载txt文件。问题是我想用总的空格而不是“”替换数据框中的NA。我使用data[is.na(data)] <- ""
d1<-c("a","","b")
d2<-c("a","a","b")
d3<-c("","","b")
d4<-c("a","c","b")
d5<-c("","b","b")
NN2<-data.frame(Name,d1,d2,d3,d4,d5)
ui <- fluidPage(
downloadLink("downloadData", "Download")
)
server <- function(input, output) {
# Our dataset
data <- NN2
data[is.na(data)] <- ""
output$downloadData <- downloadHandler(
filename = function() {
paste("data-", Sys.Date(), ".txt", sep="")
},
content = function(file) {
write.table(data, file)
}
)
}
shinyApp(ui, server)
答案 0 :(得分:1)
此帮助吗?
write.table(data, file, na = "", quote = FALSE, row.names = FALSE)