These methods allow one to extract and replace parts of the hyperSpec object. They can be used for selecting/deleting spectra, cutting the spectral range, and extracting or setting the extra data belonging to the object. Convenient shortcuts are provided for commonly used operations.

# S4 method for hyperSpec
[(x, i, j, l, ..., wl.index = FALSE, drop = FALSE)

# S4 method for hyperSpec
[[(x, i, j, l, ..., wl.index = FALSE, drop = FALSE)

# S4 method for hyperSpec
$(x, name)

# S4 method for hyperSpec
[(x, i, j, ...) <- value

# S4 method for hyperSpec
[[(x, i, j, l, wl.index = FALSE, ...) <- value

# S4 method for hyperSpec
$(x, name) <- value

Arguments

x

A hyperSpec Object.

i

Index of rows in x@data. Integer, logical, or in the case of [[ and [[<-, a nrow by 2 logical matrix or integer index matrix. In this case the indexing is done inside the spectra matrix. See the examples.

j

Index of x@data columns. Integer, logical or character. The order of columns in a hyperSpec object is not fixed and thus using integer or logical vectors may not be safe.

l

Index of wavelengths in the spectra matrix. The behavior of l depends upon the value of wl.index.

...

Ignored.

wl.index

If FALSE (the default), the values in l are taken to be wavelengths. If TRUE, the values in l are taken to be indices for the spectral matrix.

drop

For [[: drop unnecessary dimensions, see base::drop() and base::Extract(). Ignored (quietly) for [, as otherwise invalid hyperSpec objects might result.

name

Name of the data column to extract. $spc yields the spectra matrix.

value

the replacement value

Value

  • For [, [<-, [[<-, and $<- a hyperSpec object.

  • For [[ a matrix or data.frame.

  • For $ the given column of the data.frame x@data.

  • x[[]] returns the complete spectra matrix.

  • x$. returns the complete slot @data,

  • x$.. returns the data.frame in @data but without the column @data$spc containing the spectra matrix.

Details

While the parts of the hyperSpec object can be accessed directly, it is good practice to use the functions provided by the package to handle the objects rather than accessing the slots directly. This also ensures that proper (i.e. valid) objects are returned. In some cases, however, direct access to the slots can considerably speed up calculations.

The main functions to retrieve the data of a hyperSpec object are [] and [[]]. The difference between these functions is that [] returns a hyperSpec object, whereas [[]] returns a data.frame containing x$spc, the spectral data. To modify a hyperSpec object, the corresponding functions are [<- and [[<-. The first form is used to modify the entire hyperSpec object and the second form modifies the spectral data in x$spc.

hyperSpec objects are triple indexed:

  • x[i, j, l, wl.index = TRUE/FALSE]

  • x[[i, j, l, wl.index = TRUE/FALSE]]

  • i refers to rows of the @data slot. i can be integer indices or a logical vector.

  • j refers to columns of the @data slot. j can be integer indices, a logical vector or the name of a column. However, there is no guaranteed order to colnames(x) so using integer indices and logical vectors is unwise.

  • l refers to wavelengths. Note the argument wl.index which determines how l is interpreted.

  • If there is only one index given, e.g. x[1:3], it refers to the row index i. Likewise if there are only two indices given they refer to i and j.

Extraction (Getter) Actions

GetterAction
x[]Returns the entire hyperSpec object unchanged.
x[i, , ]Returns the hyperSpec object with selected rows; equivalent to x[i].
x[, j, ]Returns the hyperSpec object with empty x$spc slot. If you want the column j, x[["name"]] returns a data.frame containing j or x$name returns it as a vector.
x[, , l, wl.index = TRUE/FALSE]Returns the hyperSpec object with selected wavelengths.
x[[]]Returns the spectra matrix (x$spc).
x[[i, , ]]Returns the spectra matrix (x$spc) with selected rows.
x[[, j, ]]Returns a data.frame with the selected columns. Safest to give j as a character string.
x[[, , l, wl.index = TRUE/FALSE]]Returns the spectra matrix (x$spc) with selected wavelengths.
x$nameReturns the column name as a vector.
x$.Returns the complete data.frame x@data, with the spectra in column $spc.
x$..Returns all the extra data (x@data without x$spc).
wl()Returns the wavelengths.
labels()Returns the labels.

One can see that there are several ways to get the spectral data: x$spc, x[[]], x$... The first two forms return a matrix, while the last returns a data.frame.

Replacement (Setter) Actions

SetterAction
x[i, ,] <-Replaces the specified rows of the @data slot, including x$spc and any extra data columns. Other approaches are probably easier.
x[, j,] <-Replaces the specified columns. Safest to give j as a character string.
x[i, j] <-Replaces the specified column limited to the specified rows. Safest to give j as a character string.
x[, , l, wl.index = TRUE/FALSE] <-Replaces the specified wavelengths.
x[[i, ,]] <-Replaces the specified row of x$spc
x[[, j,]] <-As [[]] refers to just the spectral data in x$spc, this operation is not valid. See below.
x[[, , l, wl.index = TRUE/FALSE]] <-Replaces the intensity values in x$spc for the specified wavelengths.
x[[i, , l, wl.index = TRUE/FALSE]] <-Replaces the intensity values in x$spc for the specified wavelengths limited to the specified rows.
x$.. <-Sets the extra data (x@data without touching x$spc). The column names must match exactly in this case.
wl<-Sets the wavelength vector.
labels<-Sets the labels.

See also

wl2i() on conversion of wavelength ranges to indices. base::drop() and base::Extract() for details on drop.

Examples

##### Access rows using "i" (first index) # numeric index plot(flu, "spc", lines.args = list(lty = 2))
plot(flu[1:3], "spc", add = TRUE, col = "red") # select spectra
plot(flu[-(1:3)], "spc", add = TRUE, col = "blue") # delete spectra
# logical index plot(flu, "spc", lines.args = list(lty = 2))
index <- rnorm(6) > 0 index
#> [1] TRUE TRUE FALSE FALSE TRUE TRUE
plot(flu[index], "spc", add = TRUE, col = "red") # select spectra
plot(flu[!index], "spc", add = TRUE, col = "blue") # select spectra
##### Access columns using "j" (2nd index) range(faux_cell[[, "x"]]) # safest to use the name of the column
#> [1] -11.55 22.45
colnames(faux_cell[[, 1]])
#> [1] "x"
dim(faux_cell[[, c(TRUE, FALSE, FALSE)]])
#> [1] 875 2
head(faux_cell$x) # get "j" via name
#> [1] -11.55 -10.55 -9.55 -8.55 -7.55 -6.55
##### Access wavelengths using "l" (3rd index) dim(flu[[]])
#> [1] 6 181
fluA <- flu[[, , 420~450]] # matches the wavelength values dim(fluA)
#> [1] 6 61
fluB <- flu[[, , 31:91, wl.index = TRUE]] identical(fluA, fluB)
#> [1] TRUE
##### Indexing via both j and l, result is data.frame result <- flu[[, 1:2, 405 ~ 410]] result
#> spc.405 spc.405.5 spc.406 spc.406.5 spc.407 spc.407.5 spc.408 #> 1 27.15000 32.34467 33.37867 34.41933 36.53133 37.64767 38.13700 #> 2 66.80133 63.71533 66.71200 69.58233 72.52967 74.55833 77.04800 #> 3 93.14433 103.06767 106.19367 110.18633 113.24867 119.17300 121.31333 #> 4 130.66367 139.99833 143.79767 148.42000 152.13267 159.31033 165.05233 #> 5 167.26667 171.89833 177.47067 184.62467 189.75233 198.11533 205.56267 #> 6 198.43033 209.45800 215.78500 224.58700 232.52800 240.77133 248.04667 #> spc.408.5 spc.409 spc.409.5 spc.410 filename #> 1 39.17700 40.73567 41.38133 44.25133 rawdata/flu1.txt #> 2 80.25967 82.53867 84.49167 88.15167 rawdata/flu2.txt #> 3 124.67533 129.56867 134.11733 139.98667 rawdata/flu3.txt #> 4 168.68967 175.45900 181.58100 185.69233 rawdata/flu4.txt #> 5 208.41933 217.55267 224.74633 231.03567 rawdata/flu5.txt #> 6 256.89133 262.73900 270.27133 281.82867 rawdata/flu6.txt
class(result)
#> [1] "data.frame"
colnames(result)
#> [1] "spc" "filename"
##### Shortcuts # extract the spectra matrix flu[[]][1:5, 1:5] # show only a bit here
#> 405 405.5 406 406.5 407 #> [1,] 27.15000 32.34467 33.37867 34.41933 36.53133 #> [2,] 66.80133 63.71533 66.71200 69.58233 72.52967 #> [3,] 93.14433 103.06767 106.19367 110.18633 113.24867 #> [4,] 130.66367 139.99833 143.79767 148.42000 152.13267 #> [5,] 167.26667 171.89833 177.47067 184.62467 189.75233
# extract the data.frame including the spectra matrix flu$.
#> spc.405 spc.405.5 spc.406 spc.406.5 spc.407 spc.407.5 spc.408 #> 1 27.15000 32.34467 33.37867 34.41933 36.53133 37.64767 38.13700 #> 2 66.80133 63.71533 66.71200 69.58233 72.52967 74.55833 77.04800 #> 3 93.14433 103.06767 106.19367 110.18633 113.24867 119.17300 121.31333 #> 4 130.66367 139.99833 143.79767 148.42000 152.13267 159.31033 165.05233 #> 5 167.26667 171.89833 177.47067 184.62467 189.75233 198.11533 205.56267 #> 6 198.43033 209.45800 215.78500 224.58700 232.52800 240.77133 248.04667 #> spc.408.5 spc.409 spc.409.5 spc.410 spc.410.5 spc.411 spc.411.5 #> 1 39.17700 40.73567 41.38133 44.25133 44.12633 46.98067 49.08167 #> 2 80.25967 82.53867 84.49167 88.15167 91.08533 95.37233 95.53033 #> 3 124.67533 129.56867 134.11733 139.98667 145.02333 147.10367 150.53400 #> 4 168.68967 175.45900 181.58100 185.69233 190.89667 197.70833 203.64700 #> 5 208.41933 217.55267 224.74633 231.03567 236.35233 244.61233 251.95000 #> 6 256.89133 262.73900 270.27133 281.82867 287.70467 297.23500 307.59333 #> spc.412 spc.412.5 spc.413 spc.413.5 spc.414 spc.414.5 spc.415 #> 1 50.27433 50.10967 52.23167 53.03967 54.51900 56.22033 57.71933 #> 2 98.99533 101.03433 103.55800 107.02667 109.54533 111.67233 113.98733 #> 3 151.91733 158.18767 162.47900 167.57967 170.99567 176.37600 181.19767 #> 4 209.56433 214.66167 219.65333 225.73100 232.12567 236.47700 240.81533 #> 5 257.34633 265.54500 272.06333 280.74133 288.10567 291.88367 300.74000 #> 6 314.99367 324.56300 330.80033 340.89667 347.62167 355.02667 365.62333 #> spc.415.5 spc.416 spc.416.5 spc.417 spc.417.5 spc.418 spc.418.5 #> 1 59.51433 58.74500 60.09467 61.84067 62.16867 66.04933 65.24500 #> 2 117.03267 119.83500 123.49433 123.32367 127.00167 130.68067 132.35800 #> 3 181.86833 187.98933 192.12267 194.55600 198.58033 204.04367 208.43300 #> 4 247.19200 252.61167 258.44767 262.91767 269.74967 273.44567 279.34533 #> 5 307.87567 315.42967 321.89600 326.73133 334.01200 339.59933 343.86167 #> 6 374.35700 380.21733 391.40100 398.17300 405.42933 412.48400 421.27300 #> spc.419 spc.419.5 spc.420 spc.420.5 spc.421 spc.421.5 spc.422 #> 1 65.79900 66.94333 69.13600 70.92467 73.83400 74.38567 74.17333 #> 2 136.16467 138.39933 140.22433 141.04333 143.13133 147.17967 150.01200 #> 3 212.51867 215.81567 219.50867 222.67767 227.59000 229.54900 234.28167 #> 4 283.74367 290.86000 295.65200 300.38267 303.59267 307.91433 315.23467 #> 5 351.25667 357.79733 360.36000 367.96533 374.54900 381.76000 389.24100 #> 6 429.36267 433.35767 443.18733 447.88033 461.33933 467.12733 475.18967 #> spc.422.5 spc.423 spc.423.5 spc.424 spc.424.5 spc.425 spc.425.5 #> 1 75.53067 76.42967 76.13200 77.89067 79.36867 79.42733 82.02833 #> 2 153.69333 155.72800 158.47200 159.50067 160.81567 163.90967 166.25500 #> 3 236.97767 241.06967 245.41933 249.38867 251.92200 256.41200 261.64400 #> 4 319.20133 322.25767 328.22000 331.54600 337.62033 341.84300 347.36800 #> 5 397.79733 403.78367 408.02300 418.35533 420.61400 427.04333 433.33900 #> 6 481.66667 488.73567 494.01867 504.47333 515.40467 521.23867 522.64633 #> spc.426 spc.426.5 spc.427 spc.427.5 spc.428 spc.428.5 spc.429 #> 1 83.87833 83.81367 85.50667 86.50233 88.93733 88.99533 89.51500 #> 2 169.59233 170.82833 172.08767 175.21133 178.47067 179.68100 181.82867 #> 3 264.58433 268.46033 274.54733 275.68967 279.99767 283.71833 285.21700 #> 4 352.53033 358.72233 363.61833 369.33300 373.90100 377.09633 383.98500 #> 5 438.43633 449.57667 449.64833 455.43800 463.33200 471.47433 476.60033 #> 6 536.03533 544.41767 551.63333 556.71267 567.61267 572.54933 578.72667 #> spc.429.5 spc.430 spc.430.5 spc.431 spc.431.5 spc.432 spc.432.5 #> 1 90.55667 91.70633 93.57900 94.01300 94.21033 96.44200 96.62733 #> 2 184.42933 187.75600 187.93767 191.05700 192.50900 192.80100 195.55600 #> 3 290.15667 292.75667 294.99133 299.22533 301.33567 301.46200 309.15933 #> 4 386.89700 393.22067 398.54233 402.31633 405.33067 409.50400 412.68800 #> 5 480.93533 486.53833 491.91000 500.59200 502.12433 508.40733 512.70433 #> 6 587.74900 590.54867 600.42300 608.35800 614.03833 616.95567 621.87267 #> spc.433 spc.433.5 spc.434 spc.434.5 spc.435 spc.435.5 spc.436 #> 1 98.96233 98.84767 100.56833 100.44933 99.91600 99.71900 100.88633 #> 2 197.89067 198.78200 200.99467 201.52233 200.20600 204.13200 204.90433 #> 3 309.92833 310.05567 312.86500 314.62367 318.42200 323.17967 324.57933 #> 4 418.63200 418.58267 417.95567 420.19100 428.14767 428.40300 430.17300 #> 5 515.62733 522.20267 524.72467 525.20700 529.69967 531.71400 537.00600 #> 6 629.80033 633.44500 637.13233 639.16167 642.89833 648.17200 651.67900 #> spc.436.5 spc.437 spc.437.5 spc.438 spc.438.5 spc.439 spc.439.5 #> 1 101.44533 102.64267 104.22967 103.11133 104.75800 103.15833 103.94267 #> 2 203.98833 205.75600 204.81700 206.09100 208.60733 210.79667 210.58400 #> 3 325.85133 326.61767 324.63700 326.96700 327.78933 329.90967 328.28167 #> 4 431.36800 434.95500 434.42533 438.43967 439.85467 438.54167 440.27267 #> 5 538.20567 543.83567 544.08533 547.93633 552.15700 550.93500 548.20333 #> 6 654.53967 656.83267 659.77800 662.05633 663.12300 663.48200 670.47567 #> spc.440 spc.440.5 spc.441 spc.441.5 spc.442 spc.442.5 spc.443 #> 1 105.37100 105.86333 103.67967 104.09000 104.65400 105.22633 104.80433 #> 2 210.19033 210.54233 209.85933 212.82733 212.52067 212.41967 211.22233 #> 3 328.56567 331.69100 330.74933 335.06767 334.62533 334.27133 332.64733 #> 4 438.30833 440.54033 443.27967 445.88900 444.99000 446.40533 444.76700 #> 5 548.14767 550.77700 550.86067 551.78767 553.30400 552.57400 553.54533 #> 6 669.88700 670.06033 671.00800 667.61233 666.30833 669.97433 675.68300 #> spc.443.5 spc.444 spc.444.5 spc.445 spc.445.5 spc.446 spc.446.5 #> 1 105.81033 104.75800 103.88300 105.36167 105.01500 105.05933 105.34933 #> 2 215.56367 213.42467 211.15933 212.97533 213.98933 214.17200 213.47633 #> 3 333.62633 332.72400 330.82933 332.14667 334.25567 333.93800 332.78600 #> 4 445.82700 446.16433 446.24100 446.36533 442.30900 444.89333 446.92033 #> 5 551.11500 555.87400 554.84800 558.49500 556.92500 559.01233 557.12833 #> 6 675.97867 676.64200 674.73667 671.23433 673.61133 676.73533 677.49467 #> spc.447 spc.447.5 spc.448 spc.448.5 spc.449 spc.449.5 spc.450 #> 1 103.98700 105.43867 104.19667 105.09800 104.72333 106.66733 106.94967 #> 2 212.48867 211.74100 212.70467 212.94033 212.12933 213.77267 213.49733 #> 3 331.55400 331.97367 334.16567 334.10633 333.85700 336.50567 333.77567 #> 4 448.18633 446.18767 446.09267 448.20600 446.96067 446.45833 446.63067 #> 5 555.68833 553.09200 554.96233 553.30000 555.83300 555.17800 556.52367 #> 6 674.28033 676.64567 674.89067 673.09200 674.89800 671.64167 672.53167 #> spc.450.5 spc.451 spc.451.5 spc.452 spc.452.5 spc.453 spc.453.5 #> 1 104.75467 105.08267 105.30000 105.21300 104.78100 104.53867 105.13267 #> 2 213.46400 213.17067 212.83600 211.96333 208.79867 211.50633 209.47700 #> 3 334.70633 333.20267 333.36967 332.16600 330.79900 332.47633 332.63667 #> 4 448.45033 448.09967 446.22200 445.86033 443.31967 443.83833 442.67333 #> 5 554.77567 551.07633 553.91567 553.45200 550.76067 551.41767 548.26100 #> 6 672.28033 671.00033 672.87900 674.74300 672.72467 669.79100 672.00433 #> spc.454 spc.454.5 spc.455 spc.455.5 spc.456 spc.456.5 spc.457 #> 1 105.16967 104.05700 106.38533 104.07967 104.40133 102.18133 103.44167 #> 2 211.85967 213.26200 212.28367 211.77333 209.39067 208.85600 208.34033 #> 3 330.23200 329.06333 327.73533 327.03167 326.89333 327.08800 326.73833 #> 4 440.84300 444.90533 442.43233 438.76567 435.72033 436.73867 438.15267 #> 5 549.39067 553.83833 549.54067 544.38700 544.44033 543.01167 539.73833 #> 6 672.33967 668.74033 662.63333 666.29700 664.63267 659.91800 660.13033 #> spc.457.5 spc.458 spc.458.5 spc.459 spc.459.5 spc.460 spc.460.5 #> 1 101.79700 102.87167 102.38867 100.41900 101.16167 98.61133 98.42933 #> 2 206.50633 206.77733 206.64500 205.25500 201.74700 201.98800 199.57000 #> 3 324.45733 322.25233 318.61333 319.23467 318.66567 314.18900 313.58533 #> 4 432.70400 433.13733 430.09933 427.13467 421.59067 421.58900 420.52567 #> 5 538.81333 537.68600 532.22333 531.40200 527.58867 526.91933 519.80200 #> 6 656.23733 654.19500 652.31833 647.82100 643.38133 640.79033 632.11967 #> spc.461 spc.461.5 spc.462 spc.462.5 spc.463 spc.463.5 spc.464 #> 1 98.57600 98.34100 98.46733 95.14900 94.71100 95.27433 94.88433 #> 2 200.55100 198.76767 197.03300 194.14467 193.38300 193.66467 192.51267 #> 3 310.74700 311.77633 306.24567 305.31367 303.65067 299.22133 301.25333 #> 4 417.21033 414.81367 415.02733 407.90400 404.02167 401.89667 397.83033 #> 5 518.62067 515.22900 511.55500 506.87467 503.26400 498.34400 494.06167 #> 6 633.56367 627.81900 623.21133 619.99667 613.55133 606.01267 605.92100 #> spc.464.5 spc.465 spc.465.5 spc.466 spc.466.5 spc.467 spc.467.5 #> 1 93.62133 92.46567 92.11533 91.30867 89.53900 88.28100 86.13633 #> 2 190.63300 186.45567 186.05433 182.30533 182.33367 180.56933 180.50633 #> 3 296.55200 294.46667 291.52000 288.69967 286.65467 283.82400 282.00933 #> 4 395.28733 391.98100 386.99833 387.28467 379.87933 377.22867 374.34933 #> 5 491.78467 484.60533 486.67233 479.56767 475.90100 472.13100 464.54333 #> 6 599.88400 593.00650 587.40150 586.38900 581.49850 574.15100 566.49250 #> spc.468 spc.468.5 spc.469 spc.469.5 spc.470 spc.470.5 spc.471 #> 1 86.16200 86.81733 85.95767 84.06700 86.21200 83.68333 82.56867 #> 2 180.21267 175.21100 171.65000 170.41667 170.37400 169.40700 164.89000 #> 3 279.39100 274.85267 271.53567 268.85467 265.92933 261.68533 260.63400 #> 4 368.45633 365.84700 360.04467 359.29733 354.65933 350.36133 346.36533 #> 5 457.90900 455.22167 449.28400 446.34567 442.75167 438.25067 432.26667 #> 6 560.29000 559.46250 550.27850 545.54350 542.76900 528.92800 528.12900 #> spc.471.5 spc.472 spc.472.5 spc.473 spc.473.5 spc.474 spc.474.5 #> 1 82.70533 81.26033 78.75233 76.67533 77.95300 77.50700 76.16400 #> 2 164.14133 163.17333 160.98933 159.66533 157.74633 155.13467 153.23933 #> 3 258.69100 254.81867 250.93133 247.61267 247.52033 244.78833 241.26000 #> 4 343.82067 341.66833 334.16667 330.03433 328.76800 324.67567 324.62100 #> 5 427.76167 422.73000 416.02133 413.34567 408.62267 403.80533 400.32500 #> 6 519.65350 516.54950 512.45650 502.48600 499.65250 495.00100 486.49700 #> spc.475 spc.475.5 spc.476 spc.476.5 spc.477 spc.477.5 spc.478 #> 1 75.64600 76.43700 74.57033 72.87900 72.80267 71.05200 70.21367 #> 2 151.52300 149.19667 147.49467 147.49000 145.43367 144.81900 142.43867 #> 3 240.24000 238.41733 233.56600 231.26300 229.50400 228.82800 225.52900 #> 4 318.50667 314.84000 312.79333 309.28467 306.05233 304.24467 299.30133 #> 5 393.77333 393.78567 386.53867 383.86933 378.65500 373.64800 372.70233 #> 6 481.73950 476.47200 472.37900 469.25450 466.99550 457.76300 452.32300 #> spc.478.5 spc.479 spc.479.5 spc.480 spc.480.5 spc.481 spc.481.5 #> 1 69.60533 69.98967 68.78000 68.34233 67.68467 67.27700 67.04833 #> 2 142.68967 142.88100 139.83767 135.47933 135.25267 135.84567 133.55900 #> 3 221.65767 218.32400 216.50633 213.21500 215.24567 208.54933 208.86967 #> 4 295.51333 292.25100 290.55800 286.98100 285.83633 283.13467 276.48133 #> 5 368.87433 366.15533 362.89967 357.86333 354.96700 352.37067 344.31567 #> 6 450.48350 445.14500 444.27400 435.22800 430.33300 424.72000 420.74800 #> spc.482 spc.482.5 spc.483 spc.483.5 spc.484 spc.484.5 spc.485 #> 1 65.31300 64.50900 63.50567 62.18367 62.04500 62.02733 61.79900 #> 2 133.31767 132.82400 128.93033 125.20300 124.73967 124.71667 121.67833 #> 3 210.30900 205.67467 203.98400 200.07500 197.68767 197.21600 193.02933 #> 4 275.80333 272.57200 270.89733 266.44633 265.42300 262.04033 259.87533 #> 5 342.10133 339.01433 336.71533 334.59300 326.09833 324.69400 320.56700 #> 6 418.46650 414.01750 408.32400 403.85400 405.00450 394.33500 389.97750 #> spc.485.5 spc.486 spc.486.5 spc.487 spc.487.5 spc.488 spc.488.5 #> 1 60.52800 59.34200 59.12500 57.74800 57.44667 57.74267 56.27500 #> 2 120.90167 121.40600 117.66767 117.04100 115.94100 112.22900 112.72433 #> 3 191.21133 190.76267 186.57933 183.09267 182.39100 179.87400 177.13400 #> 4 256.72533 250.20833 249.26700 245.61367 240.69333 240.84900 233.99533 #> 5 315.93067 312.73200 307.94367 306.38633 298.34667 298.57433 296.05233 #> 6 384.49100 382.33700 375.08200 369.09900 366.06300 362.45350 358.99650 #> spc.489 spc.489.5 spc.490 spc.490.5 spc.491 spc.491.5 spc.492 #> 1 55.49233 54.40933 53.83267 53.26333 52.45733 52.14000 49.78433 #> 2 111.67267 109.69833 107.64067 108.05067 105.22000 102.95300 102.75833 #> 3 176.43600 173.72833 170.26000 168.65033 166.09067 164.44633 160.81267 #> 4 233.73500 230.80467 228.26600 223.37333 221.35733 218.90167 214.44667 #> 5 292.49933 285.46933 282.62833 279.92767 273.34667 267.55433 266.10100 #> 6 352.14300 348.20000 347.10650 338.79150 335.34700 330.04000 325.16200 #> spc.492.5 spc.493 spc.493.5 spc.494 spc.494.5 spc.495 filename #> 1 49.62300 48.33800 47.30400 47.16267 46.41233 45.25633 rawdata/flu1.txt #> 2 100.62800 97.96500 97.35333 96.60167 96.20600 94.61033 rawdata/flu2.txt #> 3 158.91100 156.76133 154.92067 149.53900 148.52667 145.79333 rawdata/flu3.txt #> 4 210.01767 206.01533 204.57500 201.48433 198.86733 195.86733 rawdata/flu4.txt #> 5 261.76567 259.40200 256.20067 252.06567 248.06700 246.95200 rawdata/flu5.txt #> 6 322.06850 315.64550 312.32950 307.51850 302.32550 294.64950 rawdata/flu6.txt #> c #> 1 0.05 #> 2 0.10 #> 3 0.15 #> 4 0.20 #> 5 0.25 #> 6 0.30
dim(flu$.)
#> [1] 6 3
colnames(flu$.) # = colnames(flu[])
#> [1] "spc" "filename" "c"
flu$.$spc
#> 405 405.5 406 406.5 407 407.5 408 #> [1,] 27.15000 32.34467 33.37867 34.41933 36.53133 37.64767 38.1370 #> [2,] 66.80133 63.71533 66.71200 69.58233 72.52967 74.55833 77.0480 #> [3,] 93.14433 103.06767 106.19367 110.18633 113.24867 119.17300 121.3133 #> [4,] 130.66367 139.99833 143.79767 148.42000 152.13267 159.31033 165.0523 #> [5,] 167.26667 171.89833 177.47067 184.62467 189.75233 198.11533 205.5627 #> [6,] 198.43033 209.45800 215.78500 224.58700 232.52800 240.77133 248.0467 #> 408.5 409 409.5 410 410.5 411 411.5 #> [1,] 39.17700 40.73567 41.38133 44.25133 44.12633 46.98067 49.08167 #> [2,] 80.25967 82.53867 84.49167 88.15167 91.08533 95.37233 95.53033 #> [3,] 124.67533 129.56867 134.11733 139.98667 145.02333 147.10367 150.53400 #> [4,] 168.68967 175.45900 181.58100 185.69233 190.89667 197.70833 203.64700 #> [5,] 208.41933 217.55267 224.74633 231.03567 236.35233 244.61233 251.95000 #> [6,] 256.89133 262.73900 270.27133 281.82867 287.70467 297.23500 307.59333 #> 412 412.5 413 413.5 414 414.5 415 #> [1,] 50.27433 50.10967 52.23167 53.03967 54.5190 56.22033 57.71933 #> [2,] 98.99533 101.03433 103.55800 107.02667 109.5453 111.67233 113.98733 #> [3,] 151.91733 158.18767 162.47900 167.57967 170.9957 176.37600 181.19767 #> [4,] 209.56433 214.66167 219.65333 225.73100 232.1257 236.47700 240.81533 #> [5,] 257.34633 265.54500 272.06333 280.74133 288.1057 291.88367 300.74000 #> [6,] 314.99367 324.56300 330.80033 340.89667 347.6217 355.02667 365.62333 #> 415.5 416 416.5 417 417.5 418 418.5 #> [1,] 59.51433 58.7450 60.09467 61.84067 62.16867 66.04933 65.2450 #> [2,] 117.03267 119.8350 123.49433 123.32367 127.00167 130.68067 132.3580 #> [3,] 181.86833 187.9893 192.12267 194.55600 198.58033 204.04367 208.4330 #> [4,] 247.19200 252.6117 258.44767 262.91767 269.74967 273.44567 279.3453 #> [5,] 307.87567 315.4297 321.89600 326.73133 334.01200 339.59933 343.8617 #> [6,] 374.35700 380.2173 391.40100 398.17300 405.42933 412.48400 421.2730 #> 419 419.5 420 420.5 421 421.5 422 #> [1,] 65.7990 66.94333 69.1360 70.92467 73.8340 74.38567 74.17333 #> [2,] 136.1647 138.39933 140.2243 141.04333 143.1313 147.17967 150.01200 #> [3,] 212.5187 215.81567 219.5087 222.67767 227.5900 229.54900 234.28167 #> [4,] 283.7437 290.86000 295.6520 300.38267 303.5927 307.91433 315.23467 #> [5,] 351.2567 357.79733 360.3600 367.96533 374.5490 381.76000 389.24100 #> [6,] 429.3627 433.35767 443.1873 447.88033 461.3393 467.12733 475.18967 #> 422.5 423 423.5 424 424.5 425 425.5 #> [1,] 75.53067 76.42967 76.1320 77.89067 79.36867 79.42733 82.02833 #> [2,] 153.69333 155.72800 158.4720 159.50067 160.81567 163.90967 166.25500 #> [3,] 236.97767 241.06967 245.4193 249.38867 251.92200 256.41200 261.64400 #> [4,] 319.20133 322.25767 328.2200 331.54600 337.62033 341.84300 347.36800 #> [5,] 397.79733 403.78367 408.0230 418.35533 420.61400 427.04333 433.33900 #> [6,] 481.66667 488.73567 494.0187 504.47333 515.40467 521.23867 522.64633 #> 426 426.5 427 427.5 428 428.5 429 #> [1,] 83.87833 83.81367 85.50667 86.50233 88.93733 88.99533 89.5150 #> [2,] 169.59233 170.82833 172.08767 175.21133 178.47067 179.68100 181.8287 #> [3,] 264.58433 268.46033 274.54733 275.68967 279.99767 283.71833 285.2170 #> [4,] 352.53033 358.72233 363.61833 369.33300 373.90100 377.09633 383.9850 #> [5,] 438.43633 449.57667 449.64833 455.43800 463.33200 471.47433 476.6003 #> [6,] 536.03533 544.41767 551.63333 556.71267 567.61267 572.54933 578.7267 #> 429.5 430 430.5 431 431.5 432 432.5 #> [1,] 90.55667 91.70633 93.5790 94.0130 94.21033 96.4420 96.62733 #> [2,] 184.42933 187.75600 187.9377 191.0570 192.50900 192.8010 195.55600 #> [3,] 290.15667 292.75667 294.9913 299.2253 301.33567 301.4620 309.15933 #> [4,] 386.89700 393.22067 398.5423 402.3163 405.33067 409.5040 412.68800 #> [5,] 480.93533 486.53833 491.9100 500.5920 502.12433 508.4073 512.70433 #> [6,] 587.74900 590.54867 600.4230 608.3580 614.03833 616.9557 621.87267 #> 433 433.5 434 434.5 435 435.5 436 436.5 #> [1,] 98.96233 98.84767 100.5683 100.4493 99.9160 99.7190 100.8863 101.4453 #> [2,] 197.89067 198.78200 200.9947 201.5223 200.2060 204.1320 204.9043 203.9883 #> [3,] 309.92833 310.05567 312.8650 314.6237 318.4220 323.1797 324.5793 325.8513 #> [4,] 418.63200 418.58267 417.9557 420.1910 428.1477 428.4030 430.1730 431.3680 #> [5,] 515.62733 522.20267 524.7247 525.2070 529.6997 531.7140 537.0060 538.2057 #> [6,] 629.80033 633.44500 637.1323 639.1617 642.8983 648.1720 651.6790 654.5397 #> 437 437.5 438 438.5 439 439.5 440 440.5 #> [1,] 102.6427 104.2297 103.1113 104.7580 103.1583 103.9427 105.3710 105.8633 #> [2,] 205.7560 204.8170 206.0910 208.6073 210.7967 210.5840 210.1903 210.5423 #> [3,] 326.6177 324.6370 326.9670 327.7893 329.9097 328.2817 328.5657 331.6910 #> [4,] 434.9550 434.4253 438.4397 439.8547 438.5417 440.2727 438.3083 440.5403 #> [5,] 543.8357 544.0853 547.9363 552.1570 550.9350 548.2033 548.1477 550.7770 #> [6,] 656.8327 659.7780 662.0563 663.1230 663.4820 670.4757 669.8870 670.0603 #> 441 441.5 442 442.5 443 443.5 444 444.5 #> [1,] 103.6797 104.0900 104.6540 105.2263 104.8043 105.8103 104.7580 103.8830 #> [2,] 209.8593 212.8273 212.5207 212.4197 211.2223 215.5637 213.4247 211.1593 #> [3,] 330.7493 335.0677 334.6253 334.2713 332.6473 333.6263 332.7240 330.8293 #> [4,] 443.2797 445.8890 444.9900 446.4053 444.7670 445.8270 446.1643 446.2410 #> [5,] 550.8607 551.7877 553.3040 552.5740 553.5453 551.1150 555.8740 554.8480 #> [6,] 671.0080 667.6123 666.3083 669.9743 675.6830 675.9787 676.6420 674.7367 #> 445 445.5 446 446.5 447 447.5 448 448.5 #> [1,] 105.3617 105.0150 105.0593 105.3493 103.9870 105.4387 104.1967 105.0980 #> [2,] 212.9753 213.9893 214.1720 213.4763 212.4887 211.7410 212.7047 212.9403 #> [3,] 332.1467 334.2557 333.9380 332.7860 331.5540 331.9737 334.1657 334.1063 #> [4,] 446.3653 442.3090 444.8933 446.9203 448.1863 446.1877 446.0927 448.2060 #> [5,] 558.4950 556.9250 559.0123 557.1283 555.6883 553.0920 554.9623 553.3000 #> [6,] 671.2343 673.6113 676.7353 677.4947 674.2803 676.6457 674.8907 673.0920 #> 449 449.5 450 450.5 451 451.5 452 452.5 #> [1,] 104.7233 106.6673 106.9497 104.7547 105.0827 105.3000 105.2130 104.7810 #> [2,] 212.1293 213.7727 213.4973 213.4640 213.1707 212.8360 211.9633 208.7987 #> [3,] 333.8570 336.5057 333.7757 334.7063 333.2027 333.3697 332.1660 330.7990 #> [4,] 446.9607 446.4583 446.6307 448.4503 448.0997 446.2220 445.8603 443.3197 #> [5,] 555.8330 555.1780 556.5237 554.7757 551.0763 553.9157 553.4520 550.7607 #> [6,] 674.8980 671.6417 672.5317 672.2803 671.0003 672.8790 674.7430 672.7247 #> 453 453.5 454 454.5 455 455.5 456 456.5 #> [1,] 104.5387 105.1327 105.1697 104.0570 106.3853 104.0797 104.4013 102.1813 #> [2,] 211.5063 209.4770 211.8597 213.2620 212.2837 211.7733 209.3907 208.8560 #> [3,] 332.4763 332.6367 330.2320 329.0633 327.7353 327.0317 326.8933 327.0880 #> [4,] 443.8383 442.6733 440.8430 444.9053 442.4323 438.7657 435.7203 436.7387 #> [5,] 551.4177 548.2610 549.3907 553.8383 549.5407 544.3870 544.4403 543.0117 #> [6,] 669.7910 672.0043 672.3397 668.7403 662.6333 666.2970 664.6327 659.9180 #> 457 457.5 458 458.5 459 459.5 460 460.5 #> [1,] 103.4417 101.7970 102.8717 102.3887 100.4190 101.1617 98.61133 98.42933 #> [2,] 208.3403 206.5063 206.7773 206.6450 205.2550 201.7470 201.98800 199.57000 #> [3,] 326.7383 324.4573 322.2523 318.6133 319.2347 318.6657 314.18900 313.58533 #> [4,] 438.1527 432.7040 433.1373 430.0993 427.1347 421.5907 421.58900 420.52567 #> [5,] 539.7383 538.8133 537.6860 532.2233 531.4020 527.5887 526.91933 519.80200 #> [6,] 660.1303 656.2373 654.1950 652.3183 647.8210 643.3813 640.79033 632.11967 #> 461 461.5 462 462.5 463 463.5 464 #> [1,] 98.5760 98.3410 98.46733 95.1490 94.7110 95.27433 94.88433 #> [2,] 200.5510 198.7677 197.03300 194.1447 193.3830 193.66467 192.51267 #> [3,] 310.7470 311.7763 306.24567 305.3137 303.6507 299.22133 301.25333 #> [4,] 417.2103 414.8137 415.02733 407.9040 404.0217 401.89667 397.83033 #> [5,] 518.6207 515.2290 511.55500 506.8747 503.2640 498.34400 494.06167 #> [6,] 633.5637 627.8190 623.21133 619.9967 613.5513 606.01267 605.92100 #> 464.5 465 465.5 466 466.5 467 467.5 #> [1,] 93.62133 92.46567 92.11533 91.30867 89.5390 88.2810 86.13633 #> [2,] 190.63300 186.45567 186.05433 182.30533 182.3337 180.5693 180.50633 #> [3,] 296.55200 294.46667 291.52000 288.69967 286.6547 283.8240 282.00933 #> [4,] 395.28733 391.98100 386.99833 387.28467 379.8793 377.2287 374.34933 #> [5,] 491.78467 484.60533 486.67233 479.56767 475.9010 472.1310 464.54333 #> [6,] 599.88400 593.00650 587.40150 586.38900 581.4985 574.1510 566.49250 #> 468 468.5 469 469.5 470 470.5 471 #> [1,] 86.1620 86.81733 85.95767 84.0670 86.2120 83.68333 82.56867 #> [2,] 180.2127 175.21100 171.65000 170.4167 170.3740 169.40700 164.89000 #> [3,] 279.3910 274.85267 271.53567 268.8547 265.9293 261.68533 260.63400 #> [4,] 368.4563 365.84700 360.04467 359.2973 354.6593 350.36133 346.36533 #> [5,] 457.9090 455.22167 449.28400 446.3457 442.7517 438.25067 432.26667 #> [6,] 560.2900 559.46250 550.27850 545.5435 542.7690 528.92800 528.12900 #> 471.5 472 472.5 473 473.5 474 474.5 #> [1,] 82.70533 81.26033 78.75233 76.67533 77.9530 77.5070 76.1640 #> [2,] 164.14133 163.17333 160.98933 159.66533 157.7463 155.1347 153.2393 #> [3,] 258.69100 254.81867 250.93133 247.61267 247.5203 244.7883 241.2600 #> [4,] 343.82067 341.66833 334.16667 330.03433 328.7680 324.6757 324.6210 #> [5,] 427.76167 422.73000 416.02133 413.34567 408.6227 403.8053 400.3250 #> [6,] 519.65350 516.54950 512.45650 502.48600 499.6525 495.0010 486.4970 #> 475 475.5 476 476.5 477 477.5 478 #> [1,] 75.6460 76.4370 74.57033 72.8790 72.80267 71.0520 70.21367 #> [2,] 151.5230 149.1967 147.49467 147.4900 145.43367 144.8190 142.43867 #> [3,] 240.2400 238.4173 233.56600 231.2630 229.50400 228.8280 225.52900 #> [4,] 318.5067 314.8400 312.79333 309.2847 306.05233 304.2447 299.30133 #> [5,] 393.7733 393.7857 386.53867 383.8693 378.65500 373.6480 372.70233 #> [6,] 481.7395 476.4720 472.37900 469.2545 466.99550 457.7630 452.32300 #> 478.5 479 479.5 480 480.5 481 481.5 #> [1,] 69.60533 69.98967 68.7800 68.34233 67.68467 67.2770 67.04833 #> [2,] 142.68967 142.88100 139.8377 135.47933 135.25267 135.8457 133.55900 #> [3,] 221.65767 218.32400 216.5063 213.21500 215.24567 208.5493 208.86967 #> [4,] 295.51333 292.25100 290.5580 286.98100 285.83633 283.1347 276.48133 #> [5,] 368.87433 366.15533 362.8997 357.86333 354.96700 352.3707 344.31567 #> [6,] 450.48350 445.14500 444.2740 435.22800 430.33300 424.7200 420.74800 #> 482 482.5 483 483.5 484 484.5 485 485.5 #> [1,] 65.3130 64.5090 63.50567 62.18367 62.0450 62.02733 61.7990 60.5280 #> [2,] 133.3177 132.8240 128.93033 125.20300 124.7397 124.71667 121.6783 120.9017 #> [3,] 210.3090 205.6747 203.98400 200.07500 197.6877 197.21600 193.0293 191.2113 #> [4,] 275.8033 272.5720 270.89733 266.44633 265.4230 262.04033 259.8753 256.7253 #> [5,] 342.1013 339.0143 336.71533 334.59300 326.0983 324.69400 320.5670 315.9307 #> [6,] 418.4665 414.0175 408.32400 403.85400 405.0045 394.33500 389.9775 384.4910 #> 486 486.5 487 487.5 488 488.5 489 #> [1,] 59.3420 59.1250 57.7480 57.44667 57.74267 56.2750 55.49233 #> [2,] 121.4060 117.6677 117.0410 115.94100 112.22900 112.7243 111.67267 #> [3,] 190.7627 186.5793 183.0927 182.39100 179.87400 177.1340 176.43600 #> [4,] 250.2083 249.2670 245.6137 240.69333 240.84900 233.9953 233.73500 #> [5,] 312.7320 307.9437 306.3863 298.34667 298.57433 296.0523 292.49933 #> [6,] 382.3370 375.0820 369.0990 366.06300 362.45350 358.9965 352.14300 #> 489.5 490 490.5 491 491.5 492 492.5 #> [1,] 54.40933 53.83267 53.26333 52.45733 52.1400 49.78433 49.6230 #> [2,] 109.69833 107.64067 108.05067 105.22000 102.9530 102.75833 100.6280 #> [3,] 173.72833 170.26000 168.65033 166.09067 164.4463 160.81267 158.9110 #> [4,] 230.80467 228.26600 223.37333 221.35733 218.9017 214.44667 210.0177 #> [5,] 285.46933 282.62833 279.92767 273.34667 267.5543 266.10100 261.7657 #> [6,] 348.20000 347.10650 338.79150 335.34700 330.0400 325.16200 322.0685 #> 493 493.5 494 494.5 495 #> [1,] 48.3380 47.30400 47.16267 46.41233 45.25633 #> [2,] 97.9650 97.35333 96.60167 96.20600 94.61033 #> [3,] 156.7613 154.92067 149.53900 148.52667 145.79333 #> [4,] 206.0153 204.57500 201.48433 198.86733 195.86733 #> [5,] 259.4020 256.20067 252.06567 248.06700 246.95200 #> [6,] 315.6455 312.32950 307.51850 302.32550 294.64950
# extract the data.frame minus the spectra matrix flu$..
#> filename c #> 1 rawdata/flu1.txt 0.05 #> 2 rawdata/flu2.txt 0.10 #> 3 rawdata/flu3.txt 0.15 #> 4 rawdata/flu4.txt 0.20 #> 5 rawdata/flu5.txt 0.25 #> 6 rawdata/flu6.txt 0.30
colnames(flu$..)
#> [1] "filename" "c"
##### Indexing via matrices # indexing the spectra matrix with index matrix nrow by 2 # hyperSpec converts numeric matrices to integers for indexing ind <- matrix(c(1, 2, 4, 406, 405.5, 409), ncol = 2) ind
#> [,1] [,2] #> [1,] 1 406.0 #> [2,] 2 405.5 #> [3,] 4 409.0
flu[[ind]]
#> [1] 33.37867 63.71533 175.45900
# same as just above, but using wl.index ind <- matrix(c(1, 2, 4, c(3, 2, 9)), ncol = 2) ind
#> [,1] [,2] #> [1,] 1 3 #> [2,] 2 2 #> [3,] 4 9
flu[[ind, wl.index = TRUE]]
#> [1] 33.37867 63.71533 175.45900
# indexing via a logical matrix (applied to spectra matrix) summary(flu[[flu < 125]])
#> Min. 1st Qu. Median Mean 3rd Qu. Max. #> 27.15 66.94 90.56 85.06 104.08 124.74
## replacement functions spc <- flu if (FALSE) { spc$. } spc[, "c"] <- 16:11 ## be careful: plot(spc)
spc [] <- 6:1 spc$..
#> filename c #> 1 6 6 #> 2 5 5 #> 3 4 4 #> 4 3 3 #> 5 2 2 #> 6 1 1
plot(spc)
spc <- flu [, , 405 ~ 410] spc[[]]
#> 405 405.5 406 406.5 407 407.5 408 #> [1,] 27.15000 32.34467 33.37867 34.41933 36.53133 37.64767 38.1370 #> [2,] 66.80133 63.71533 66.71200 69.58233 72.52967 74.55833 77.0480 #> [3,] 93.14433 103.06767 106.19367 110.18633 113.24867 119.17300 121.3133 #> [4,] 130.66367 139.99833 143.79767 148.42000 152.13267 159.31033 165.0523 #> [5,] 167.26667 171.89833 177.47067 184.62467 189.75233 198.11533 205.5627 #> [6,] 198.43033 209.45800 215.78500 224.58700 232.52800 240.77133 248.0467 #> 408.5 409 409.5 410 #> [1,] 39.17700 40.73567 41.38133 44.25133 #> [2,] 80.25967 82.53867 84.49167 88.15167 #> [3,] 124.67533 129.56867 134.11733 139.98667 #> [4,] 168.68967 175.45900 181.58100 185.69233 #> [5,] 208.41933 217.55267 224.74633 231.03567 #> [6,] 256.89133 262.73900 270.27133 281.82867
spc[[3]] <- -spc[[3]] spc[[]]
#> 405 405.5 406 406.5 407 407.5 408 #> [1,] 27.15000 32.34467 33.37867 34.41933 36.53133 37.64767 38.1370 #> [2,] 66.80133 63.71533 66.71200 69.58233 72.52967 74.55833 77.0480 #> [3,] -93.14433 -103.06767 -106.19367 -110.18633 -113.24867 -119.17300 -121.3133 #> [4,] 130.66367 139.99833 143.79767 148.42000 152.13267 159.31033 165.0523 #> [5,] 167.26667 171.89833 177.47067 184.62467 189.75233 198.11533 205.5627 #> [6,] 198.43033 209.45800 215.78500 224.58700 232.52800 240.77133 248.0467 #> 408.5 409 409.5 410 #> [1,] 39.17700 40.73567 41.38133 44.25133 #> [2,] 80.25967 82.53867 84.49167 88.15167 #> [3,] -124.67533 -129.56867 -134.11733 -139.98667 #> [4,] 168.68967 175.45900 181.58100 185.69233 #> [5,] 208.41933 217.55267 224.74633 231.03567 #> [6,] 256.89133 262.73900 270.27133 281.82867
spc[[, , 405:410]] <- -spc[[, , 405:410]] spc[[]]
#> 405 405.5 406 406.5 407 407.5 #> [1,] -27.15000 32.34467 -33.37867 34.41933 -36.53133 37.64767 #> [2,] -66.80133 63.71533 -66.71200 69.58233 -72.52967 74.55833 #> [3,] 93.14433 -103.06767 106.19367 -110.18633 113.24867 -119.17300 #> [4,] -130.66367 139.99833 -143.79767 148.42000 -152.13267 159.31033 #> [5,] -167.26667 171.89833 -177.47067 184.62467 -189.75233 198.11533 #> [6,] -198.43033 209.45800 -215.78500 224.58700 -232.52800 240.77133 #> 408 408.5 409 409.5 410 #> [1,] -38.1370 39.17700 -40.73567 41.38133 -44.25133 #> [2,] -77.0480 80.25967 -82.53867 84.49167 -88.15167 #> [3,] 121.3133 -124.67533 129.56867 -134.11733 139.98667 #> [4,] -165.0523 168.68967 -175.45900 181.58100 -185.69233 #> [5,] -205.5627 208.41933 -217.55267 224.74633 -231.03567 #> [6,] -248.0467 256.89133 -262.73900 270.27133 -281.82867
spc[[, , 405 ~ 410]] <- -spc[[, , 405 ~ 410]] ## indexing with logical matrix spc <- flu [, , min ~ 410] spc < 125
#> 405 405.5 406 406.5 407 407.5 408 408.5 409 409.5 410 #> [1,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [2,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE #> [3,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE #> [4,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [5,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE #> [6,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
spc[[spc < 125]] <- NA spc[[]]
#> 405 405.5 406 406.5 407 407.5 408 408.5 #> [1,] NA NA NA NA NA NA NA NA #> [2,] NA NA NA NA NA NA NA NA #> [3,] NA NA NA NA NA NA NA NA #> [4,] 130.6637 139.9983 143.7977 148.4200 152.1327 159.3103 165.0523 168.6897 #> [5,] 167.2667 171.8983 177.4707 184.6247 189.7523 198.1153 205.5627 208.4193 #> [6,] 198.4303 209.4580 215.7850 224.5870 232.5280 240.7713 248.0467 256.8913 #> 409 409.5 410 #> [1,] NA NA NA #> [2,] NA NA NA #> [3,] 129.5687 134.1173 139.9867 #> [4,] 175.4590 181.5810 185.6923 #> [5,] 217.5527 224.7463 231.0357 #> [6,] 262.7390 270.2713 281.8287
## indexing with n by 2 matrix ind <- matrix(c(1, 2, 4, 406, 405.5, 409), ncol = 2) ind
#> [,1] [,2] #> [1,] 1 406.0 #> [2,] 2 405.5 #> [3,] 4 409.0
spc[[ind]] <- 3 spc[[]]
#> 405 405.5 406 406.5 407 407.5 408 408.5 #> [1,] NA NA 3.0000 NA NA NA NA NA #> [2,] NA 3.0000 NA NA NA NA NA NA #> [3,] NA NA NA NA NA NA NA NA #> [4,] 130.6637 139.9983 143.7977 148.4200 152.1327 159.3103 165.0523 168.6897 #> [5,] 167.2667 171.8983 177.4707 184.6247 189.7523 198.1153 205.5627 208.4193 #> [6,] 198.4303 209.4580 215.7850 224.5870 232.5280 240.7713 248.0467 256.8913 #> 409 409.5 410 #> [1,] NA NA NA #> [2,] NA NA NA #> [3,] 129.5687 134.1173 139.9867 #> [4,] 3.0000 181.5810 185.6923 #> [5,] 217.5527 224.7463 231.0357 #> [6,] 262.7390 270.2713 281.8287
ind <- matrix(c(1, 2, 4, 4:6), ncol = 2) ind
#> [,1] [,2] #> [1,] 1 4 #> [2,] 2 5 #> [3,] 4 6
spc[[ind, wl.index = TRUE]] <- 9999 spc[[]]
#> 405 405.5 406 406.5 407 407.5 408 408.5 #> [1,] NA NA 3.0000 9999.0000 NA NA NA NA #> [2,] NA 3.0000 NA NA 9999.0000 NA NA NA #> [3,] NA NA NA NA NA NA NA NA #> [4,] 130.6637 139.9983 143.7977 148.4200 152.1327 9999.0000 165.0523 168.6897 #> [5,] 167.2667 171.8983 177.4707 184.6247 189.7523 198.1153 205.5627 208.4193 #> [6,] 198.4303 209.4580 215.7850 224.5870 232.5280 240.7713 248.0467 256.8913 #> 409 409.5 410 #> [1,] NA NA NA #> [2,] NA NA NA #> [3,] 129.5687 134.1173 139.9867 #> [4,] 3.0000 181.5810 185.6923 #> [5,] 217.5527 224.7463 231.0357 #> [6,] 262.7390 270.2713 281.8287
spc$.
#> spc.405 spc.405.5 spc.406 spc.406.5 spc.407 spc.407.5 spc.408 #> 1 NA NA 3.0000 9999.0000 NA NA NA #> 2 NA 3.0000 NA NA 9999.0000 NA NA #> 3 NA NA NA NA NA NA NA #> 4 130.6637 139.9983 143.7977 148.4200 152.1327 9999.0000 165.0523 #> 5 167.2667 171.8983 177.4707 184.6247 189.7523 198.1153 205.5627 #> 6 198.4303 209.4580 215.7850 224.5870 232.5280 240.7713 248.0467 #> spc.408.5 spc.409 spc.409.5 spc.410 filename c #> 1 NA NA NA NA rawdata/flu1.txt 0.05 #> 2 NA NA NA NA rawdata/flu2.txt 0.10 #> 3 NA 129.5687 134.1173 139.9867 rawdata/flu3.txt 0.15 #> 4 168.6897 3.0000 181.5810 185.6923 rawdata/flu4.txt 0.20 #> 5 208.4193 217.5527 224.7463 231.0357 rawdata/flu5.txt 0.25 #> 6 256.8913 262.7390 270.2713 281.8287 rawdata/flu6.txt 0.30
spc$z <- 1:6 spc
#> hyperSpec object #> 6 spectra #> 4 data columns #> 11 data points / spectrum #> wavelength: lambda/nm [numeric] 405.0 405.5 ... 410 #> data: (6 rows x 4 columns) #> 1. spc: I[fl]/"a.u." [matrix, array11] NA NA ... 281.8287 + NA #> 2. filename: filename [character] rawdata/flu1.txt rawdata/flu2.txt ... rawdata/flu6.txt #> 3. c: c / (mg / l) [numeric] 0.05 0.10 ... 0.3 #> 4. z: z [integer] 1 2 ... 6
spc$z <- list(1:6, "z / a.u.")