Membuat atau memaksa objek bertipe "numerik". is.numeric adalah pengujian yang lebih umum terhadap suatu objek yang dapat ditafsirkan sebagai angka.
numeric(length = 0)
as.numeric(x, …)
is.numeric(x)
| Parameter | Deskripsi |
|---|---|
length |
A non-negative integer specifying the desired length. Double values will be coerced to integer: supplying an argument of length other than one is an error. |
x |
object to be coerced or tested. |
… |
further arguments passed to or from other methods. |
# NOT RUN {
as.numeric(c("-.1"," 2.7 ","B")) # (-0.1, 2.7, NA) + warning
as.numeric(factor(5:10)) # not what you'd expect
f <- factor(1:5)
## what you typically meant and want:
as.numeric(as.character(f))
## the same, considerably (for long factors) more efficient:
as.numeric(levels(f))[f]
# }