0
votes

i'm exporting a data frame with write.csv.

Before making the data frame, i've cleaned every vector with:

ColumnA <-   gsub("^\\s+|\\s+$", "", ColumnA)

After using data.frame(), i use this to export the csv file:

write.csv(DataFrameABC, "DataFrameABC.csv",
      row.names = F, fileEncoding = "UTF-8")

Problem: i get a blank line in between every line.

I don't need those blank lines.

enter image description here

#

EDIT 1:

I've just wanted to put some sample of the data so i used this:

DataFrameABC2 <- DataFrameABC[1:3,]

But when i use str() on this new data frame, i get surprisingly:

    > str(DataFrameABC2)
'data.frame':   3 obs. of  3 variables:
 $ Celulares_Telefonia_Marca        : Factor w/ 223 levels "\n2Cool","\n4THM2",..: 116 178 139
 $ Celulares_Telefonia_Producto     : Factor w/ 2039 levels "?\"iLuv - Case Mummy & Ninja para iPhone 5/5s ACIL7T327 - ...",..: 1155 1647 1308
 $ Celulares_Telefonia_Precio_actual: Factor w/ 412 levels "S/. 1,019.00",..: 8 356 378

I mean: 3 obs, and then Factors with houndreds and thousends of levels?

What is going on¿?

EDIT 2: SAMPLE DATA

setting data.frame (stringsAsFactors = F) reduced the dput output, however blank lines still appear when openning the CSV in Excel:

  structure(list(Celulares_Telefonia_Marca = c("\nLG", "\nSamsung", 
"\nMotorola"), Celulares_Telefonia_Producto = c("LG G Flex 32GB 13MP 4G LTE Desbloqueado - Plateado", 
"Samsung Galaxy S4 Mini Duos I9192 8GB 8MP Desbloqueado - ...", 
"Motorola - Moto G xt1068 Duos 2da Generación 8GB 8MP Des..."
), Celulares_Telefonia_Precio_actual = c("S/. 1,149.00", "S/. 749.00", 
"S/. 839.00")), .Names = c("Celulares_Telefonia_Marca", "Celulares_Telefonia_Producto", 
"Celulares_Telefonia_Precio_actual"), row.names = c(NA, 3L), class = "data.frame")
1
Please provide a reproducible example of the problem. - Rich Scriven
About the factors with many levels, you should probably use as.is = TRUE or stringsAsFactors = FALSE when reading the data/creating the data frame. I don't think it's related to the blank lines though. - Molx
@Molx, thanks. You are right. It has nothing to do with the blank lines in Excel. - Omar Gonzales

1 Answers

2
votes

Your problem is that you have newlines embedded in the data.

From your dput output:

structure(list(Celulares_Telefonia_Marca = c("\nLG", "\nSamsung",

Those \n characters are within the strings for the data in the first column. These are creating newlines in the output. That is giving you blank lines in Excel.