iemisc (version 0.9.8)

volsphere: Sphere volume

Description

This function computes the volume of a sphere using a given radius.

Usage

volsphere(r)

Arguments

r

numeric vector, matrix, data.frame, or data.table that contains the radius of a sphere.

Value

volume of a sphere (as L^3 units) as an R object: a numeric vector or a named numeric vector if using a named object (matrix, data.frame, or data.table).

Details

The radius of a sphere is "the integral of the surface area of a sphere."

Volume of a sphere is expressed as

$$V = \frac{4}{3}\pi r^3$$

V

the volume of a sphere

r

the radius of a sphere

References

Wikimedia Foundation, Inc. Wikipedia, 30 December 2015, <U+201C>Volume<U+201D>, https://en.wikipedia.org/wiki/Volume.

Examples

Run this code
# NOT RUN {
library("iemisc")
library("data.table")

volsphere(3) # in

volsphere(4.5) # in


x <- c(3, 4, 0.2, 12, 34, 7.5) # cm
volsphere(x)


# using a matrix of the numeric vector x
mat1 <- matrix(data = x, nrow = length(x), ncol = 1, byrow = FALSE,
       dimnames = list(c(rep("", length(x))), "Radius"))
volsphere(mat1)


# using a data.frame of the numeric vector x
df1 <- data.frame(x)
volsphere(df1)


# using a data.table of the numeric vector x
df2 <- data.table(x)
volsphere(df2)




# }

Run the code above in your browser using DataLab