Examples for 'base::vector'


Vectors - Creation, Coercion, etc

Aliases: vector as.vector as.vector.data.frame as.vector.factor as.vector.POSIXlt is.vector atomic

Keywords: classes

### ** Examples

df <- data.frame(x = 1:3, y = 5:7)
## Error:
try(as.vector(data.frame(x = 1:3, y = 5:7), mode = "numeric"))
Error in as.vector(x, mode = mode) : 
  'list' object cannot be coerced to type 'double'
x <- c(a = 1, b = 2)
is.vector(x)
[1] TRUE
as.vector(x)
[1] 1 2
all.equal(x, as.vector(x)) ## FALSE
[1] "names for target but not for current"
###-- All the following are TRUE:
is.list(df)
[1] TRUE
! is.vector(df)
[1] TRUE
! is.vector(df, mode = "list")
[1] TRUE
is.vector(list(), mode = "list")
[1] TRUE

[Package base version 4.2.3 Index]