Description Usage Details Author(s) See Also Examples
Saves a zoo
object to a file with a named extension
1 |
@param z zoo
a zoo object (coredata
can be multi-column)
@param file character
filename in which to save z
with the file extension being one of:
"psv"pipe-separated values
"csv"comma-separated values
"txt"tab-separated values
"xls"Excel spreadsheet
"Rdata"R binary file
Thomas P. Harte
save
,
write.table
,
write.csv
,
write.xls
,
get_file_ext
,
zoo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | require(zoo)
n<- 10
dates<- seq(as.Date("2008-10-31"), by=1, len=n)
z<- zoo(matrix(c(rnorm(n, sd=.1), rnorm(n, sd=.5), rnorm(n, sd=1)), nc=3),
order.by=dates)
basename<- tempfile("z")
# save as a PSV file:
filename<- paste(basename, ".psv", sep="")
save_zoo(z, file=filename)
# note: column names added by default:
file.show(filename)
# add column names:
colnames(z)<- c("one", "two", "three")
# this time save as a CSV file:
filename<- paste(basename, ".csv", sep="")
save_zoo(z, file=filename)
file.show(filename)
# this time save as a TXT file:
filename<- paste(basename, ".txt", sep="")
save_zoo(z, file=filename)
file.show(filename)
filename<- paste(basename, ".Rdata", sep="")
save_zoo(z, file=filename)
# get rid of 'z':
rm(z)
# restore 'z':
print(load(filename))
# restore 'z' as 'foo':
foo<- load_as(filename)
stopifnot(identical(z, foo))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.