select_range: Select a subset of rows of a data set to be retained

View source: R/select_range.r

select_rangeR Documentation

Select a subset of rows of a data set to be retained

Description

This function selects which rows of a data set should be included. Either the begin or the end argument need to be specified. The column does not need to be sorted for this function to work. Values are included if they are >= begin and <= end, if specified, for the specified column. Values that are NA are never removed by this function.

Usage

select_range(av_state, subset_id = 1, column, begin, end)

Arguments

av_state

an object of class av_state

subset_id

either an integer subset index or the the value for the id_field column that was used in the group_by function. The subset_id argument is required if the data set is grouped into multiple data sets (i.e., if the group_by function was used), in which case the function works on the specified data subset.

column

specifies which column the begin and end values should be taken over. This argument is optional, and if it is missing, id_field used in order_by will be used.

begin

indicates which values should be included. Values that are >= begin are included. This argument is optional if end is specified.

end

indicates which values should be included. Values that are <= end are included. This argument is optional if begin is specified.

Value

This function returns the modified av_state object.

Examples

## Not run: 
av_state <- load_file("../data/input/pp2 nieuw compleet_64dagen.sav",log_level=3)
av_state <- order_by(av_state,'tijdstip')
print(av_state)
av_state$data[[1]]['tijdstip']
# default column is the order_by column in this case:
av_state <- select_range(av_state,begin=20,end=40)
print(av_state)
av_state$data[[1]]['tijdstip']

av_state <- load_file("../data/input/pp2 nieuw compleet_64dagen.sav",log_level=3)
print(av_state)
av_state$data[[1]]['lnSomPHQ']
# now only retain rows with 0 <= lnSomPHQ <= 2
av_state <- select_range(av_state,column='lnSomPHQ',begin=0,end=2)
print(av_state)
av_state$data[[1]]['lnSomPHQ']

## End(Not run)

roqua/autovar documentation built on Jan. 21, 2023, 7:37 p.m.