Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

LOCS

Select Time Series Indexes


Description

This function returns the indexes 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', ...)

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.

Value

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

See Also

Examples

#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)

bimets

Time Series and Econometric Modeling

v1.5.3
GPL-3
Authors
Andrea Luciani [aut, cre], Roberto Stok [aut], Bank of Italy [cph]
Initial release
2021-02-04

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.