as.smet: Coerces an object to a 'smet-class' object

Description Usage Arguments Examples

View source: R/as.smet.R

Description

The method as.smet coerces an object or a charachter string to a SMET. If the object is

as.smet

as.smet

as.smet

as.smet

as.smet

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
as.smet(object, ...)

as.smet(object, ...)

## S4 method for signature 'character'
as.smet(object, ...)

## S4 method for signature 'data.frame'
as.smet(object, mult = NA, offset = NA,
  date.field = "timestamp", station.field = "station_id",
  header.fields = c("longitude", "latitude", "station_id", "altitude",
  "location"), variables = NULL, force.multistation = FALSE,
  metaparam = attr(object, "metaparam"), file = NA, ...)

## S4 method for signature 'list'
as.smet(object, ...)

## S4 method for signature 'smet'
as.smet(object, ...)

Arguments

object

the object to be coerced

...

further arguments

mult, offset

numeric vectors of unit multiplier and offset respectivaly

date.field

field name used for date and time. Default is "timestamp", as used for SMET format.

station.field

field name used for station ID. Default is "station_id", as used for SMET format.

header.fields

names used for the SMET header. Defaults are c("longitude","latitude","station_id" ,"altitude","location")

variables

(optional) selection of variables hich can be exported to SMET formats. It is used only in case of two or more stations.

force.multistation

logical value. If it is TRUE the method is forced to return a list of SMET objects even in case of only one station

metaparam

metedata optional data frame containig meta info on variables. It can be entered as an attribute of object. See the structure of metaparam of meteofrance.It must contains SMET_ID,SMET_UNIT_MULTIPLIER,SMET_UNIT_OFFSET columns/fields.

file

full filename of the reference SMET filename (not considered when object is character .

Examples

 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
35
36
37
38
39
data(meteofrance)


## Choose a particular station 
station_id <-  unique(meteofrance$station_id)[3]




variables <- c("timestamp","DW","VW","TA","TD","RH","MFR_rr24",
      "MFR_tn12","MFR_tn24","MFR_tx12","MFR_tx24","HS","HS_fresh")
header <- c("longitude","latitude","station_id" ,"altitude","location")
names(header) <- header



data <- meteofrance[meteofrance$station_id==station_id,c(header,variables)]
metaparam <- attr(meteofrance,"metaparam")
metaparam <- metaparam[metaparam$SMET_ID %in% names(data),]
header <- lapply(X=header,FUN=function(x,data) {data[1,x]},data=data)
data <- data[,variables]
attr(data,"header") <- header
attr(data,"metaparam") <- metaparam

sm <- as.smet(data)

# In case of multiple station, it return a list of SMET-class objects: 

## This opton works for more than one station, 
#in case of one station this works too only if it is FORCED!

sm_multi <- as.smet(meteofrance,variables=variables)


onestation <- meteofrance[meteofrance$station_id=="07499",]
sm_o <- as.smet(onestation,variables=variables,force.multistation=TRUE)


 

RSMET documentation built on April 24, 2018, 5:04 p.m.