vektor menghasilkan vektor dengan panjang dan modus tertentu. as.vector, sebuah generik, mencoba untuk memaksakan argumennya ke dalam vektor mode mode (defaultnya adalah memaksa ke mode vektor mana pun yang paling nyaman): jika hasilnya atomik, semua atribut akan dihapus. is.vector mengembalikan TRUE jika x adalah vektor dari mode yang ditentukan tidak memiliki atribut selain nama. Ia mengembalikan FALSE jika tidak.
vector(mode = "logical", length = 0)
as.vector(x, mode = "any")
is.vector(x, mode = "any")
| Parameter | Deskripsi |
|---|---|
mode |
character string naming an atomic mode or "list" or "expression" or (except for vector) "any". Currently, is.vector() allows any type (see typeof) for mode, and when mode is not "any", is.vector(x, mode) is almost the same as typeof(x) == mode. |
length |
a non-negative integer specifying the desired length. For a long vector, i.e., length > .Machine$integer.max, it has to be of type "double". Supplying an argument of length other than one is an error. |
x |
an R object. |
# NOT RUN {
df <- data.frame(x = 1:3, y = 5:7)
## Error:
try(as.vector(data.frame(x = 1:3, y = 5:7), mode = "numeric"))
x <- c(a = 1, b = 2)
is.vector(x)
as.vector(x)
all.equal(x, as.vector(x)) ## FALSE
###-- All the following are TRUE:
is.list(df)
! is.vector(df)
! is.vector(df, mode = "list")
is.vector(list(), mode = "list")
# }