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    88
#> 1942    91
#> 1943    91
#> 1944    91
#> 1945    98
#> 1946   103
#> 1947   106
#> 1948    97
#> 1949   101
#> 1950    99
#> 1951    96
#> 1952    93
#> 1953    90
#> 1954    96
#> 1955   102
#> 1956    94
#> 1957    98
#> 1958    96
#> 1959   100
#> 1960   106
#> 1961   116
#> 1962   135
#> 1963   119
#> 1964   108
#> 1965   111
#> 1966   111
#> 1967   117
#> 1968   113
#> 1969   114
#> 1970   104
#> 1971   106
#> 1972    90
#> 1973    89
#> 1974    72
#> 1975    79
#> 1976    88
#> 1977    94
#> 1978    91
#> 1979    98
#> 1980   103
#> 1981    96
#> 1982   102
#> 1983   105
#> 1984    94
#> 1985   110
#> 1986    95
#> 1987    92
#> 1988    90
#> 1989    97
#> 1990    91
#> 1991   103
#> 1992   110
#> 1993    94
#> 1994    98
#> 1995    89
#> 1996    92
#> 1997    92
#> 1998   102
#> 1999   108
#> 2000   100
trs_select(rwl, series = "trs_2", rownames_to_years = TRUE)
#>      trs_2 year
#> 1941    75 1941
#> 1942    84 1942
#> 1943    85 1943
#> 1944    88 1944
#> 1945    97 1945
#> 1946    98 1946
#> 1947   100 1947
#> 1948    88 1948
#> 1949    85 1949
#> 1950    98 1950
#> 1951    99 1951
#> 1952   104 1952
#> 1953   104 1953
#> 1954    99 1954
#> 1955   104 1955
#> 1956    98 1956
#> 1957   102 1957
#> 1958    99 1958
#> 1959    96 1959
#> 1960   103 1960
#> 1961   110 1961
#> 1962   121 1962
#> 1963   116 1963
#> 1964   105 1964
#> 1965   100 1965
#> 1966   106 1966
#> 1967   101 1967
#> 1968   115 1968
#> 1969   122 1969
#> 1970   122 1970
#> 1971   112 1971
#> 1972    98 1972
#> 1973    92 1973
#> 1974    73 1974
#> 1975    88 1975
#> 1976    84 1976
#> 1977    89 1977
#> 1978    96 1978
#> 1979   100 1979
#> 1980   101 1980
#> 1981    96 1981
#> 1982    98 1982
#> 1983    98 1983
#> 1984    87 1984
#> 1985    94 1985
#> 1986    89 1986
#> 1987    91 1987
#> 1988    90 1988
#> 1989    97 1989
#> 1990    90 1990
#> 1991    97 1991
#> 1992   103 1992
#> 1993    91 1993
#> 1994   104 1994
#> 1995    95 1995
#> 1996   102 1996
#> 1997    97 1997
#> 1998   101 1998
#> 1999   104 1999
#> 2000   101 2000

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