[R] Arbirtrary column names with write.csv
Uwe Ligges
ligges at statistik.tu-dortmund.de
Tue Mar 3 15:27:59 CET 2009
Rafael Laboissiere wrote:
> Is there a way to prevent write.csv to transform the column names a la
> make.names? I mean, if I write the code:
>
> x <- structure (NULL)
> x [["a+b"]] <- c (1,2)
> write.csv (x, file = "foo.csv", row.names = FALSE, quote = FALSE)
your x is not a data.frame, hence write.csv() (or better, write.table())
converts your *list* x to a data.frame implicitly by using as.data.frame
(and this tries to convert names to more regular names by make.names()).
You can avoid it by either working on data.frames or stop the
make.names() conversion by forcing the data.frame in advance as in:
write.csv (as.data.frame(x, optional=TRUE), file = "foo.csv",
row.names = FALSE, quote = FALSE)
Uwe Ligges
> I get in foo.csv:
>
> a.b
> 1
> 2
>
> but I want:
>
> a+b
> 1
> 2
>
> Any suggestions?
>
> Cheers,
>
More information about the R-help
mailing list