RLink`
RLink`

RVector

RVector[type,data,attributes]

represents an internal form of an R vector in RLink.

Details and Options

  • Possible values for type are: "integer", "double", "complex", "logical", and "character".
  • data must be a one-dimensional list, whose elements must be all of the same type:
  • "integer"Integer
    "double"Real
    "complex"Complex
    "logical"True|False
    "character"String
  • In addition, missing elements are allowed, represented by Missing[].
  • attributes must have the form RAttributes["name1":> value1,]], where values of attributes can be any R objects handled by RLink.
  • Multidimensional R arrays are represented by RVector, with the dimensions attribute "dim" necessarily present among the vector attributes.

Examples

Basic Examples  (10)

This represents the vector of integers:

Unless there are some extra attributes present in a given R vector, you can usually use a simpler and more familiar Wolfram Language notation, representing vectors as (possibly nested) lists, for all RLink-related operations, so the above would just be equivalent to:

The form involving RVector is, however, more "fundamental", since all expressions are translated into this form before being sent to R, and from this form when obtained from R. The "direct translation" is done with the function ToRForm:

You can also see how multidimensional arrays are formed:

This represents an array of real numbers:

Here is a string (character) array:

A complex matrix:

A logical vector:

An array with missing elements:

Note that vectors can only contain elements of the same native type. The RLink automatic type detection will interpret a list with elements of different types as an R list (RList), rather than an R vector:

You can send your vectors to R in this form as well:

In fact, this is the actual form used to send a vector to R, even when it is initially expressed in more succinct notation ({1,2,3} here).

Add more attributes (properties) to your vector:

The result is expressed in the Wolfram Language:

Note the RObject head. In contrast to heads used for "internal" RLink representation of R objects, such as RVector, RList, and RNull, the head RObject represents the "final" Wolfram Language-side version of an R object, being just a generic container. You can use ToRForm to see the "internal" representation, which involves RVector, since the resulting object is still a vector:

Wolfram Research (2012), RVector, Wolfram Language function, https://reference.wolfram.com/language/RLink/ref/RVector.html.

Text

Wolfram Research (2012), RVector, Wolfram Language function, https://reference.wolfram.com/language/RLink/ref/RVector.html.

CMS

Wolfram Language. 2012. "RVector." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/RLink/ref/RVector.html.

APA

Wolfram Language. (2012). RVector. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/RLink/ref/RVector.html

BibTeX

@misc{reference.wolfram_2024_rvector, author="Wolfram Research", title="{RVector}", year="2012", howpublished="\url{https://reference.wolfram.com/language/RLink/ref/RVector.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_rvector, organization={Wolfram Research}, title={RVector}, year={2012}, url={https://reference.wolfram.com/language/RLink/ref/RVector.html}, note=[Accessed: 21-November-2024 ]}