R/findVars.R
findVars.Rd
If you want to look at the variability of a number of columns and you want to disregard those that are constant. Like for findCovs, by can be of arbitrary length.
findVars(data, by = NULL, cols.id, as.fun = NULL)
data.frame in which to look for covariates
optional covariates will be searched for in combinations of values in these columns. Often by will be either empty or ID. But it can also be both say c("ID","DRUG") or c("ID","TRT").
Deprecated. Use by instead.
The default is to return a data.table if data is a data.table and return a data.frame in all other cases. Pass a function in as.fun to convert to something else. If data is not a data.table, the default can be configured using NMdataConf.
a data set with as many rows as in data.
Use this to exclude columns that are constant within by. If by=ID, this could be to get only time-varying covariates.
Other DataCreate:
NMorderColumns()
,
NMstamp()
,
NMwriteData()
,
addTAPD()
,
findCovs()
,
flagsAssign()
,
flagsCount()
,
mergeCheck()
,
tmpcol()
dt1 <- data.frame(ID=c(1,1,2,2),
OCC=c(1,2,1,2),
## ID level
eta1=c(1,1,3,3),
## occasion level
eta2=c(1,3,1,5),
## not used
eta3=0
)
## model level
findCovs(dt1)
#> eta3
#> 1 0
## ID level
findCovs(dt1,"ID")
#> ID eta1 eta3
#> 1 1 1 0
#> 2 2 3 0
## acual ID level
findVars(findCovs(dt1,"ID"))
#> ID eta1
#> 1 1 1
#> 2 2 3
## occasion level
findCovs(findVars(dt1,"ID"),c("ID","OCC"))
#> ID OCC eta2
#> 1 1 1 1
#> 2 1 2 3
#> 3 2 1 1
#> 4 2 2 5