Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206278

How do I create a constructor function in R?

$
0
0

I am attempting to create a constructor function for an object using the S3 00 system in R.

The arguments of the function should only be r where r is a k × 1 vector that contains the radial measurements of fungi.

The constructor function should return an object that is a vector corresponding to r with class equal to growth.

Here is some data,

"theta","r"
0,4
0.31,2.07
0.63,2.15
0.94,3.08
1.26,4.09
1.57,2.39
1.88,1.96
2.2,3.72
2.51,4.72
2.83,2.87
3.14,1.67
3.46,3.51
3.77,4.37
4.08,2.24
4.4,2.23
4.71,4.18
5.03,3.12
5.34,2.67
5.65,2.19
5.97,3.16

So I assume the function starts similar to the following?

growth <- function(x) {
r <- as.vector(x)
class(r) <- "growth"
r
}

Viewing all articles
Browse latest Browse all 206278

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>