1

I am working with an S4 Hyperspec Object in R composed of wavelengths and corresponding different absorbance spectra datasets. I would like to select a wavelength and print out the corresponding absorbance per specific spectra.

But I'm not sure how to go about doing that.

Any advice?

I'm not super knowledgeable about object-oriented programming...

Thank you!

Lil Coder
  • 23
  • 4
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Oct 24 '18 at 19:09

1 Answers1

0

You can use @ or slot:

#define new s4 class
myS4Class <- setClass(
  "myS4Class", 
  slots = c(
   slot1 = "character", 
   slot2 = "numeric"
  )
)

#make an instance of the class
x <- new("myS4Class", slot1 = "foo", slot2 = rnorm(5))

x can now be indexed as below:

x@slot1
#> [1] "foo"

slot(x, "slot2")
#> [1]  0.2391963 -0.3398150  2.1760187  1.1890521 -0.1659958
dave-edison
  • 3,666
  • 7
  • 19