Bắt đầu ngayBắt đầu miễn phí

R functions in Julia

You've seen how to use Python functions in Julia, and R is much the same. You use the RCall package which was previously imported, and then use the rimport macro to import the package. Previously you imported base, which is the collection of base functions included in R.

In this lesson you need to define two vectors x and y using standard Julia square bracket syntax. Then the next step is to reverse the order of the vector y, and finally you will plot x vs y on a graph.

Bài tập này là một phần của khóa học

Intermediate Julia

Xem khóa học

Hướng dẫn bài tập

  • Create two vectors in Julia, one with the values one through four, and the other with values five through eight.
  • Reverse the order of the vector y using the R function rev, passing y as an argument.
  • Plot x vs y on using the R plot function.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

using RCall
@rimport base as r_base

# Define two vectors, x and y, with values one to four and five to eight
x = [____, ____, ____, ____]
y = [____, ____, ____, ____]

# Reverse the order of the values in y using R
y = ____.____(____)

# Plot x and y using R
r_base.____(____, ____)
Chỉnh sửa và Chạy Mã