I need to export a dataframe from R in CSV format, with some cells having integer(0) values, and other are lists (stored in the dataframe using df$B[k]=list(vector)
)
A B C
Comp1 integer(0) c(17, 15)
Comp2 integer(0) integer(0)
Comp3 c(15, 14) integer(0)
Comp4 15 c(12, 13, 14)
Comp5 c(16, 13, 12) integer(0)
When exported in CSV with fwrite(df, "data.csv")
, value of column n is shifted to column n-1 if the value of the cell of the column n-1 is integer(0) .
I tried :
df$B <- as.character(df$B)
df$B[df$B == "integer(0)"] <- "."
But as some cells contain lists, I cannot use as.character
and replace "integer(0)" by Something else as it will mess with some cells (list are vectors with ',' in it which will be interpreted as tab when converted with as.character
and exported to CSV).
Any way to work around that ?