csv2climatol | R Documentation |
climatol
input formatThis function helps to prepare the climatol
input files when the users
have their data in a single CSV file, as the output of xls2csv().
csv2climatol(csvfile, datacol=6:8, stnfile=csvfile, stncol=1:5, varcli,
anyi=NA, anyf=NA, mindat=NA, sep=',', dec='.', na.strings='NA',
dateformat='%Y-%m-%d', cf=1, ndec=1, header=TRUE)
csvfile |
name of the CSV file containing the data. |
datacol |
column(s) holding station codes, dates and data. |
stnfile |
name of the CSV file containing station codes, names and coordinates (if these data are not in the csvfile). |
stncol |
columns holding longitudes, latitudes, elevations and station codes and names. |
varcli |
short name of the climatic variable under study. |
anyi |
first year to study. |
anyf |
last year to study. |
mindat |
minimum required number of data per station (by default, 60 monthly data or 365 daily data). |
sep |
data separator (',' by default: Comma Separated Values). |
dec |
decimal point ('.' by default). |
na.strings |
strings coding missing data ('NA' by default). |
dateformat |
format of dates (if not in separate columns.
Default: |
cf |
conversion factor to apply if data units need to be changed. |
ndec |
no. of decimals to round to. |
header |
|
If datacol
holds 4 (or 5) values, dates are expected to appear as
year, month (and days) in separate columns. Otherwise, dates will be provided
as character strings (see parameter dateformat
). Subdaily data may
provide dates/times in POSIX format (e.g.:
dateformat='%Y-%m-%d %H:%M:%S'
).
Alternatively, hourly data does not need to specify minutes and seconds, as
in '%Y%m%d%H'
. (Note that this function only works if data are
taken at regular intervals.)
Station codes, names and coordinates can go in a separate file
stnfile
. At least coordinates and station codes must be present in
either csvfile
or stnfile
. Put a zero for any inexistent
columns. Example when stnfile
contains only, in this order, latitudes,
longitudes and station names: stncol=c(2,1,0,3,0)
.
Note that if a stnfile is provided, then sep, dec, na.strings and header
defined for csvfile will also be applied to stnfile.
xls2csv
, homogen
## Set a temporal working directory:
wd <- tempdir()
wd0 <- setwd(wd)
## Create origin and destination directories and copy example input files:
dir.create('dir1'); dir.create('dir2')
file.copy(exampleFiles('p064.xlsx'),'dir1')
file.copy(exampleFiles('p082.xlsx'),'dir1')
file.copy(exampleFiles('p084.xlsx'),'dir1')
## Create input files for csv2climatol with the function xls2csv:
xls2csv('dir1','dir2','RR')
## Add bogus coordinates and elevations to the station file:
est=read.table('xls_RR_stations.csv',sep=',')
est=data.frame(1:3,21:23,101:103,est)
write.table(est,'xls_RR_stations.csv',sep=',',row.names=FALSE,col.names=FALSE)
## Now run the example of csv2climatol:
csv2climatol('xls_RR_data.csv', datacol=1:5, stnfile='xls_RR_stations.csv',
varcli='RR',header=FALSE)
## Return to user's working directory:
setwd(wd0)
## Input and output files can be found in directory:
print(wd)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.