makeDASData {DASplusR} | R Documentation |
The function makeDASData
takes a data object of class data.frame
and transforms it to an object of class
DASData
. Much auxiliary information is added in form of attributes.
makeDASData(data, data.name=NULL, header=NA, comment_main=NA, ident=NA, coordinates=c(NA,NA), ranges=c(NA,NA,NA,NA), units=rep(NA,ncol(data)), meth_analysis=rep(NA,ncol(data)), detect_limits=rep(NA,ncol(data)), comment_var=rep(NA,ncol(data)), subsets=list(), sel_subsets=list(), sel_variables=list() )
data |
a data object of class data.frame or DASData (usually the Active Data Set |
data.name |
the name of the data object in the .GlobalEnv environment, if NULL it is deparsed from
data |
header |
character string specifying the header |
comment_main |
character string with comments to the data object |
indent |
name of variable containing the identifications of the observations (rows) |
coordinates |
names of variables containing the x- resp. y-coordinates |
ranges |
ranges of the x- resp. y-coordinates: xmin, xmax, ymin, ymax |
units |
vector of character strings containing the units of the variables |
meth_analysis |
vector of character strings containing the 'method of analysis' of the variables |
detect_limits |
vector of character strings containing the 'detection limits' of the variables |
comment_var |
vector of character strings containing comments on each variable |
subsets |
vector of character strings containing comments on each variable |
ind |
one of:
In any case the index information will be stored as integers identifying rows. |
overwrite |
boolean; a flag giving the function the right to overwrite existing subsets called 'subname' |
The function adds 'attributes' to the data object, if they do not exist already. The information added can be accessed via 'attributes(dat)'.
If 'ind' is a character expression giving a condition on columns, with usage of type makeSubset(dat,subname,ind="col1<15") the data object is automatically attached (see '?attach' for details) if a column name is referred directly as in makeSubset(dat,subname,ind="col1<15").
The standard usage would be as makeSubset(dat,subname,ind="dat$col1<15") or makeSubset(dat,subname,ind="dat[,1]<15")
The flag 'overwrite' is FLASE by default and can be set to TRUE if an existing subset named 'subname' is to be replaced by the one specified through 'ind'. In case there are more subsets called 'subname' the first one in the occurence is replaced if 'overwrite' is set to TRUE. If 'overwrite' is FALSE and there is an existing subset named 'subname', an error message appeares, there are no changes applied.
As mentioned above, the subset index information is stored as integers identifying rownumbers. The common usage for getting subsets as data objects would therefore be (as script) dat[attributes(dat)$subsets$subname$indices,].
The generated data object of class 'DASData' with subsets is written to the working environment ('.GlobalEnv') during the execution of the function. Therefore, to examine the changes, you have to look for a object names identically like 'dat' in the working environment. See the examples for details.
The function returns TRUE or FALSE regarding the success of the workflow. The new object is copied to the working environment and is visible there.
There are no missing values allowed, the overwrite flag is optional and by default FALSE. An empty subset-attribute is an empty list (list()).
Stefan Schnabl stefan.schnabl@gmail.com
'removeSubsets', 'selectSubsets', 'makeDASData', 'attributes', 'attr'
# example data object of class data.frame attach(test) makeSubset(test,"HighNatrium","Na>4") makeSubset(dat,"Rows",1:3) makeSubset(dat,"Rows2",c(1,3,5)) makeSubset(dat,"SpecialRows",c(T,F,T,F,T)) makeSubset(dat,"SpecialRows2",c(0,1,1,0,0)) makeSubset(dat,"Rownames",c("1","2")) # access subsets dat[attributes(test)$subsets$HighNatrium$indices,] # delete specific subsets removeSubsets(test,c(1,3,5)) # delete all removeSubsets(test,"all")