[英]How to save an R data.frame as CSV with no spaces?
I have the following data.frame
that I am saving as CSV
file.我有以下
data.frame
保存为CSV
文件。 When the data.frame
is saved as CSV
I see one point space after the Text
component (see the image).当
data.frame
保存为CSV
我会在Text
组件后面看到一个点空间(见图)。 How to avoid the space creation while saving data.frame
as CSV
?如何在将
data.frame
保存为CSV
时避免空间创建? Thank you谢谢
library(lubridate)
library(tidyverse)
DF <- data.frame(Date = seq(as.Date("2001-01-01"), to = as.Date("2001-12-31"), by = "days"), Flow = runif(365, 1, 5)) %>%
mutate(Year = year(Date), Month = month(Date), Day = day(Date), JDay = yday(Date), Text = rep("FLOW_OUT_",365)) %>%
mutate(Format = paste(Text,JDay,"_",Year)) %>%
select(8) %>%
write.csv(file = "Format.csv")
We can use paste0
instead of paste
to avoid creating the spaces as the default sep
option in paste
is sep= " "
我们可以使用
paste0
而不是paste
来避免创建空格,因为paste
的默认sep
选项是sep= " "
...
mutate(Format = paste0(Text,JDay,"_",Year))
...
-full code -完整代码
DF <- data.frame(Date = seq(as.Date("2001-01-01"), to = as.Date("2001-12-31"),
by = "days"), Flow = runif(365, 1, 5)) %>%
mutate(Year = year(Date), Month = month(Date),
Day = day(Date), JDay = yday(Date), Text = rep("FLOW_OUT_",365)) %>%
mutate(Format = paste0(Text,JDay,"_",Year)) %>%
select(8)
Or another option is making use of sep
argument in paste
或者另一种选择是在
paste
使用sep
参数
DF <- data.frame(Date = seq(as.Date("2001-01-01"), to = as.Date("2001-12-31"),
by = "days"), Flow = runif(365, 1, 5)) %>%
mutate(Year = year(Date), Month = month(Date),
Day = day(Date), JDay = yday(Date), Text = rep("FLOW_OUT_",365)) %>%
mutate(Format = paste(Text,JDay,"_",Year, sep="")) %>%
select(8)
-output -输出
head(DF)
# Format
#1 FLOW_OUT_1_2001
#2 FLOW_OUT_2_2001
#3 FLOW_OUT_3_2001
#4 FLOW_OUT_4_2001
#5 FLOW_OUT_5_2001
#6 FLOW_OUT_6_2001
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.