[R] How to write a Surv object to a csv-file?
Heinz Tuechler
tuechler at gmx.at
Fri Dec 19 20:04:10 CET 2008
Dear All,
trying to write a data.frame, containing Surv objects to a csv-file I get
"Error in dimnames(X) <- list(dn[[1L]], unlist(collabs, use.names = FALSE)) :
length of 'dimnames' [2] not equal to array extent".
See example below.
May be, I overlooked something, but I expected
that also data.frames containing Surv objects may be written to csv files.
Is there a better way to write to csv files?
Thanks,
Heinz Tüchler
### write Surv-object in csv-file
library(survival)
## create example data
soa <- Surv(1:5, c(0, 0, 1, 0, 1))
df.soa <- data.frame(soa)
write.csv(df.soa, 'df.soa.csv') ## works as I expected
read.csv('df.soa.csv') ## works as I expected
df.soa2 <- data.frame(soa, soa2=soa)
write.csv(df.soa2, 'df.soa2.csv') ## works as I expected
read.csv('df.soa2.csv') ## works as I expected
char1 <- letters[1:5]
df.soac <- data.frame(soa, char1)
write.csv(df.soac, 'df.soac.csv') ## generates the following error message:
Error in dimnames(X) <- list(dn[[1L]], unlist(collabs, use.names = FALSE)) :
length of 'dimnames' [2] not equal to array extent
df.csoa <- data.frame(char1, soa)
write.csv(df.csoa, 'df.soac.csv') ## generates the following error message:
Error in dimnames(X) <- list(dn[[1L]], unlist(collabs, use.names = FALSE)) :
length of 'dimnames' [2] not equal to array extent
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status Patched
major 2
minor 8.0
year 2008
month 11
day 10
svn rev 46884
language R
version.string R version 2.8.0 Patched (2008-11-10 r46884)
> sessionInfo()
R version 2.8.0 Patched (2008-11-10 r46884)
i386-pc-mingw32
locale:
LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252
attached base packages:
[1] splines stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] survival_2.34-1
More information about the R-help
mailing list