How to access the slots of an S4 object in R

北战南征 提交于 2019-12-04 16:25:05

问题


I'm working with wavelets on a program and I'm used the package wavelets to create the DWT of a time series using the function dwt. This function returns an object of class dwt, which is a S4 object with many slots: W, V, levels, filter, and so on.

How can I access the W's as a vector?


回答1:


@ will let you access the slots of an S4 object.

So if your object is called wave, then wave@W should get you your vector.

Note that often the best way to do this is to not access the slot directly but rather through an accessor function (e.g. coefs() rather than digging out the coefficients with $ or @). However, often such functions do not exist so you have to access the slots directly. This will mean that your code breaks if the internal implementation changes, however.



来源:https://stackoverflow.com/questions/13099780/how-to-access-the-slots-of-an-s4-object-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!