Coerces a Vector

coerceVector(v, type)

Source

Declaration: src/include/Rinternals.h and src/include/Rdefines.h

Implementation: src/main/coerce.c

Arguments

v

(SEXP) An R object.

type

(SEXPTYPE) An macro constant of length one.

Value

coerceVector() returns an SEXP object of type SEXPTYPE

type.

C API

#include <Rinternals.h>
SEXP Rf_coerceVector(SEXP, SEXPTYPE)
#define coerceVector        Rf_coerceVector

Related macros:

#include <Rdefines.h>
#define AS_LOGICAL(x)       Rf_coerceVector(x,LGLSXP)
#define AS_INTEGER(x)       Rf_coerceVector(x,INTSXP)
#define AS_NUMERIC(x)       Rf_coerceVector(x,REALSXP)
#define AS_CHARACTER(x)     Rf_coerceVector(x,STRSXP)
#define AS_COMPLEX(x)       Rf_coerceVector(x,CPLXSXP)
#define AS_VECTOR(x)        Rf_coerceVector(x,VECSXP)
#define AS_LIST(x)      Rf_coerceVector(x,VECSXP)
#define AS_RAW(x)       Rf_coerceVector(x,RAWSXP)

R API

library(base)

x <- 1:5
y_integer   <- as.integer(x)
y_logical   <- as.logical(x)
y_numeric   <- as.numeric(x)
y_character <- as.character(x)