RLink`
RLink`

RSet

RSet[var,expr]

assigns the value of the Mathematica expression expr to a variable var in the R workspace, returning back the value of expr upon success and $Failed upon failure.

更多信息和选项

  • Use RSet to send Mathematica expressions to R.
  • The variable name var must be a string, but is not restricted to be the name of a valid R variable. It can actually be any piece of R code, which represents a legal lhs for the purposes of assignments in R (it is an L-value).
  • The expression expr must be of the type convertible to R. Normally, you can use the ToRForm function to obtain an internal RLink representation for Mathematica expressions you want to send to R, and at the same time test whether or not your expression is legal.
  • RSet works with both the short and long (internal) forms of the expression expr. The form of an expression that is returned is the same as the one used for expr.

范例

打开所有单元关闭所有单元

基本范例  (5)

Send a single number to R:

Now send a vector:

Add these in R:

Change the dimensions of the vector v in R:

Now v becomes a matrix:

Send another matrix to R:

Compute a matrix product in R:

Do the same in Mathematica:

Send a nested list to R (which will be stored as an R list):

Test the type of R lst variable:

Assign a different expression to the first part of the list:

Test:

Sending an expression that cannot be converted to one of the R types fails:

You can see that also by using ToRForm:

Neat Examples  (1)

Start with a text:

Split it into characters:

Send it to R:

Use R data frames to compute frequencies of letters:

Frequencies can specifically be extracted, for example, like this:

Wolfram Research (2012),RSet,Wolfram 语言函数,https://reference.wolfram.com/language/RLink/ref/RSet.html.

文本

Wolfram Research (2012),RSet,Wolfram 语言函数,https://reference.wolfram.com/language/RLink/ref/RSet.html.

CMS

Wolfram 语言. 2012. "RSet." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/RLink/ref/RSet.html.

APA

Wolfram 语言. (2012). RSet. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/RLink/ref/RSet.html 年

BibTeX

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

BibLaTeX

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