Learn R Programming

bimets (version 4.0.3)

LOCS: Select Time Series Indices

Description

This function returns the indices of the input TRUE elements. The input can be either an array or a time series. The result is usually used as a structured index to produce a new array.

Usage

LOCS(x=NULL, options='ALL', ...)

Value

This function returns a numerical array built with the indices of the values that are TRUE in the input boolean array or in the input boolean time series.

Arguments

x

This function accepts as input a boolean array or a boolean time series, often as the result of a logic comparison between an expression and a numerical array or a numerical time series:
e.g. LOCS(c(a,b,c,...)>=k); LOCS(ts==j);
LOCS(ts<expr); LOCS(is.na(ts)); etc...

options

A selection option can refine the result:
ALL: (default) all the TRUE indices will be returned in the output.
UNIQUE: return the index of the unique TRUE result; if there are multiple TRUE results then an error will be thrown.
FIRST: return the first TRUE result.
LAST: return the last TRUE result.

...

Backward compatibility.

See Also

NOELS
is.bimets
BIMETS indexing
TSERIES
GETYEARPERIOD
NOELS
NAMELIST
INTS
TSINFO
TABIT
ELIMELS

Examples

Run this code

	#create ts
	n<-10
	ts1<-TSERIES((1:n),START=c(2000,1),FREQ=1)
	print(LOCS(ts1>7,options='FIRST')) #print 8
	
	#generate error: print LOCS(): input has more than one TRUE element.
	tryCatch({print(LOCS(ts1>=3,options='UNIQUE'));},error=function(e){print(e$message);})
	
	print(LOCS(is.na(c(1,2,NA,4,5,6,7,NA,NA)))) #print c(3,8,9)

Run the code above in your browser using DataLab