Returns the first and last "parts" (rows or members) of a spectrum,
dataframe, vector, function, table or ftable. In other words, the combined
output from methods head
and tail
.
Usage
head_tail(x, n, ...)
# Default S3 method
head_tail(x, n = 3L, ...)
# S3 method for class 'data.frame'
head_tail(x, n = 3L, ...)
# S3 method for class 'matrix'
head_tail(x, n = 3L, ...)
# S3 method for class '`function`'
head_tail(x, n = 6L, ...)
# S3 method for class 'table'
head_tail(x, n = 6L, ...)
# S3 method for class 'ftable'
head_tail(x, n = 6L, ...)
Value
An object (usually) like x
but smaller, except when
n = 0
. For ftable
objects x
, a transformed
format(x)
.
Details
The value returned by head_tail()
is equivalent to row
binding the the values returned by head()
and tail()
,
although not implemented in this way. The same specializations as defined
in package 'utils' for head()
and tail()
have been
implemented.
Methods (by class)
head_tail(default)
:head_tail(data.frame)
:head_tail(matrix)
:head_tail(`function`)
:head_tail(table)
:head_tail(ftable)
:
Note
For some types of input, like functions, the output may be confusing,
however, we have opted for consistency with existing functions. The code is
in part a revision of that of head()
and tail()
from package
‘utils’. This method is especially useful when checking spectral
data, as both ends are of interest.
head_tail()
methods for function, table and ftable classes, are
wrappers for head() method.
See also
head
, and compare the examples and the values
returned to the examples below.
Examples
head_tail(1:20)
#> [1] 1 2 3 18 19 20
head_tail(1:20, 12)
#> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
head_tail(1:20, -7)
#> [1] 8 9 10 11 12 13
head_tail(1:20, -10)
#> integer(0)
head_tail(letters)
#> [1] "a" "b" "c" "x" "y" "z"
head_tail(sun.spct)
#> Object: source_spct [6 x 3]
#> Wavelength range 280-800 nm, step 0.9230769-516.1538 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1]
#> --
#> # A tibble: 6 × 3
#> w.length s.e.irrad s.q.irrad
#> <dbl> <dbl> <dbl>
#> 1 280 0 0
#> 2 281. 0 0
#> 3 282. 0 0
#> 4 798 0.424 0.00000283
#> 5 799 0.419 0.00000280
#> 6 800 0.407 0.00000272
head_tail(sun.spct, 6)
#> Object: source_spct [12 x 3]
#> Wavelength range 280-800 nm, step 0.9230769-510.3846 nm
#> Label: sunlight, simulated
#> Measured on 2010-06-22 09:51:00 UTC
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1]
#> --
#> # A tibble: 12 × 3
#> w.length s.e.irrad s.q.irrad
#> <dbl> <dbl> <dbl>
#> 1 280 0 0
#> 2 281. 0 0
#> 3 282. 0 0
#> 4 283. 0 0
#> 5 284. 0 0
#> 6 285. 0 0
#> 7 795 0.415 0.00000276
#> 8 796 0.408 0.00000272
#> 9 797 0.414 0.00000276
#> 10 798 0.424 0.00000283
#> 11 799 0.419 0.00000280
#> 12 800 0.407 0.00000272
head_tail(sun.data)
#> w.length s.e.irrad s.q.irrad
#> 1 293 2.609665e-06 6.391823e-12
#> 2 294 6.142401e-06 1.509586e-11
#> 3 295 2.176175e-05 5.366463e-11
#> 506 798 4.236281e-01 2.825921e-06
#> 507 799 4.185850e-01 2.795778e-06
#> 508 800 4.069055e-01 2.721171e-06
head_tail(as.matrix(sun.data))
#> w.length s.e.irrad s.q.irrad
#> [1,] 293 2.609665e-06 6.391823e-12
#> [2,] 294 6.142401e-06 1.509586e-11
#> [3,] 295 2.176175e-05 5.366463e-11
#> [4,] 798 4.236281e-01 2.825921e-06
#> [5,] 799 4.185850e-01 2.795778e-06
#> [6,] 800 4.069055e-01 2.721171e-06
head_tail(sun_evening.spct)
#> Object: source_spct [6 x 3]
#> containing 2 spectra in long form
#> Wavelength range 290-1000 nm, step 0.34-708.38 nm
#> Label: cosine.hour.9
#> time.01 measured on 2023-06-12 18:38:00.379657 UTC
#> time.05 measured on 2023-06-12 18:42:00.769065 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 6 × 3
#> w.length s.e.irrad spct.idx
#> <dbl> <dbl> <fct>
#> 1 290 0 time.01
#> 2 290. 0 time.01
#> 3 291. 0 time.01
#> 4 999. 0.0328 time.05
#> 5 1000. 0.0324 time.05
#> 6 1000. 0.0322 time.05
head_tail(sun_evening.mspct, 1L)
#> Object: source_mspct [2 x 1]
#> --- Member: time.01 ---
#> Object: source_spct [1,593 x 2]
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> Measured on 2023-06-12 18:38:00.379657 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1,593 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 290 0
#> 2 290. 0
#> 3 291. 0
#> 4 291. 0
#> 5 292. 0
#> 6 292. 0
#> 7 293. 0
#> 8 293. 0
#> 9 294. 0
#> 10 294. 0
#> # ℹ 1,583 more rows
#> --- Member: time.05 ---
#> Object: source_spct [1,593 x 2]
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> Measured on 2023-06-12 18:42:00.769065 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1,593 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 290 0
#> 2 290. 0
#> 3 291. 0
#> 4 291. 0
#> 5 292. 0
#> 6 292. 0
#> 7 293. 0
#> 8 293. 0
#> 9 294. 0
#> 10 294. 0
#> # ℹ 1,583 more rows
#>
#> --- END ---