Skip to contents

Extracts one or more tree-ring series (columns) from a data frame of class "rwl". Optionally adds the rownames (assumed to be years) as a column.

Usage

trs_select(x, series, rownames_to_years = FALSE, trim = FALSE)

Arguments

x

A data.frame of class "rwl", where each column is a tree-ring width series and rownames represent years.

series

A character string or vector specifying the name(s) of the series (columns) to extract.

rownames_to_years

Logical. If TRUE, the rownames of x (years) are added as a column named years.

trim

Logical. If TRUE, leading and trailing all-NA rows are removed using trs_trim().

Value

A data.frame with the selected series. If rownames_to_years = TRUE, the result will have an additional year column. If trim = TRUE, leading and trailing all-NA rows are removed. If a single series is selected, returns a single-column data frame.

Examples

rwl <- trs_pseudo_rwl(n_series = 5, series_length = 60, end_date = 2000)

# Select single series
trs_select(rwl, series = "trs_1")
#>      trs_1
#> 1941   118
#> 1942   105
#> 1943   100
#> 1944    85
#> 1945    90
#> 1946    85
#> 1947    94
#> 1948    88
#> 1949    90
#> 1950    90
#> 1951    82
#> 1952   103
#> 1953   100
#> 1954    99
#> 1955    95
#> 1956    99
#> 1957    98
#> 1958    96
#> 1959   109
#> 1960   107
#> 1961   103
#> 1962    97
#> 1963    90
#> 1964    99
#> 1965    96
#> 1966    87
#> 1967   100
#> 1968    87
#> 1969    83
#> 1970    93
#> 1971    91
#> 1972    98
#> 1973   106
#> 1974   105
#> 1975   106
#> 1976   106
#> 1977   102
#> 1978    93
#> 1979    92
#> 1980    88
#> 1981    81
#> 1982    91
#> 1983    87
#> 1984   105
#> 1985    79
#> 1986    89
#> 1987    90
#> 1988   100
#> 1989   101
#> 1990   107
#> 1991   110
#> 1992   114
#> 1993   107
#> 1994   104
#> 1995    91
#> 1996    98
#> 1997   107
#> 1998    88
#> 1999    89
#> 2000    92
trs_select(rwl, series = "trs_2", rownames_to_years = TRUE)
#>      trs_2 year
#> 1941   112 1941
#> 1942   108 1942
#> 1943    92 1943
#> 1944    90 1944
#> 1945    98 1945
#> 1946   101 1946
#> 1947   102 1947
#> 1948    92 1948
#> 1949    94 1949
#> 1950    88 1950
#> 1951    80 1951
#> 1952    95 1952
#> 1953    86 1953
#> 1954   104 1954
#> 1955   101 1955
#> 1956   106 1956
#> 1957    92 1957
#> 1958    91 1958
#> 1959   103 1959
#> 1960   107 1960
#> 1961   100 1961
#> 1962    92 1962
#> 1963    84 1963
#> 1964    86 1964
#> 1965    98 1965
#> 1966    91 1966
#> 1967   102 1967
#> 1968    93 1968
#> 1969    82 1969
#> 1970    96 1970
#> 1971    99 1971
#> 1972   100 1972
#> 1973   103 1973
#> 1974   105 1974
#> 1975   103 1975
#> 1976    93 1976
#> 1977    98 1977
#> 1978    87 1978
#> 1979    89 1979
#> 1980    87 1980
#> 1981    79 1981
#> 1982    83 1982
#> 1983    80 1983
#> 1984   103 1984
#> 1985    88 1985
#> 1986   100 1986
#> 1987   105 1987
#> 1988   111 1988
#> 1989   107 1989
#> 1990   106 1990
#> 1991   110 1991
#> 1992   112 1992
#> 1993   107 1993
#> 1994    97 1994
#> 1995    86 1995
#> 1996    98 1996
#> 1997    97 1997
#> 1998    73 1998
#> 1999    73 1999
#> 2000    83 2000

# Select multiple series
trs_select(rwl, series = c("trs_1", "trs_2"))
#>      trs_1 trs_2
#> 1941   118   112
#> 1942   105   108
#> 1943   100    92
#> 1944    85    90
#> 1945    90    98
#> 1946    85   101
#> 1947    94   102
#> 1948    88    92
#> 1949    90    94
#> 1950    90    88
#> 1951    82    80
#> 1952   103    95
#> 1953   100    86
#> 1954    99   104
#> 1955    95   101
#> 1956    99   106
#> 1957    98    92
#> 1958    96    91
#> 1959   109   103
#> 1960   107   107
#> 1961   103   100
#> 1962    97    92
#> 1963    90    84
#> 1964    99    86
#> 1965    96    98
#> 1966    87    91
#> 1967   100   102
#> 1968    87    93
#> 1969    83    82
#> 1970    93    96
#> 1971    91    99
#> 1972    98   100
#> 1973   106   103
#> 1974   105   105
#> 1975   106   103
#> 1976   106    93
#> 1977   102    98
#> 1978    93    87
#> 1979    92    89
#> 1980    88    87
#> 1981    81    79
#> 1982    91    83
#> 1983    87    80
#> 1984   105   103
#> 1985    79    88
#> 1986    89   100
#> 1987    90   105
#> 1988   100   111
#> 1989   101   107
#> 1990   107   106
#> 1991   110   110
#> 1992   114   112
#> 1993   107   107
#> 1994   104    97
#> 1995    91    86
#> 1996    98    98
#> 1997   107    97
#> 1998    88    73
#> 1999    89    73
#> 2000    92    83
trs_select(rwl, series = c("trs_1", "trs_3", "trs_5"), rownames_to_years = TRUE)
#>      trs_1 trs_3 trs_5 year
#> 1941   118   112   117 1941
#> 1942   105   111   117 1942
#> 1943   100    98   109 1943
#> 1944    85    96   101 1944
#> 1945    90    96   113 1945
#> 1946    85    92    97 1946
#> 1947    94   105   100 1947
#> 1948    88    99    88 1948
#> 1949    90    97    91 1949
#> 1950    90    97    84 1950
#> 1951    82    87    77 1951
#> 1952   103   106    94 1952
#> 1953   100    99    90 1953
#> 1954    99   111   105 1954
#> 1955    95   107   102 1955
#> 1956    99   112   112 1956
#> 1957    98   104    91 1957
#> 1958    96    96    91 1958
#> 1959   109   110    99 1959
#> 1960   107   119   110 1960
#> 1961   103   114   107 1961
#> 1962    97    96   101 1962
#> 1963    90    93   105 1963
#> 1964    99    99   115 1964
#> 1965    96   101   106 1965
#> 1966    87    95    89 1966
#> 1967   100   110   101 1967
#> 1968    87   106    93 1968
#> 1969    83    94    87 1969
#> 1970    93   106    97 1970
#> 1971    91   105   103 1971
#> 1972    98   110   107 1972
#> 1973   106   104   110 1973
#> 1974   105   100   106 1974
#> 1975   106   100   101 1975
#> 1976   106    96    96 1976
#> 1977   102   105   102 1977
#> 1978    93    97    90 1978
#> 1979    92    97    94 1979
#> 1980    88    88    92 1980
#> 1981    81    81    84 1981
#> 1982    91    85    83 1982
#> 1983    87    83    81 1983
#> 1984   105    97    97 1984
#> 1985    79    85    77 1985
#> 1986    89    96    90 1986
#> 1987    90   107   103 1987
#> 1988   100   107   117 1988
#> 1989   101   112   111 1989
#> 1990   107   117   115 1990
#> 1991   110   116   113 1991
#> 1992   114   120   110 1992
#> 1993   107   116   109 1993
#> 1994   104   108   103 1994
#> 1995    91    97    89 1995
#> 1996    98   107    94 1996
#> 1997   107   108   101 1997
#> 1998    88    85    76 1998
#> 1999    89    86    74 1999
#> 2000    92   101    88 2000