MulaiMulai sekarang secara gratis

Boiler plate

As you saw in the previous exercise, the code below does not compile.

#include <Rcpp.h>
using namespace Rcpp ; 

double twice(double x){
    return x + x
}

Let's modify it.

Latihan ini adalah bagian dari kursus

Optimizing R Code with Rcpp

Lihat Kursus

Petunjuk latihan

  • Fix the syntax error on the function's return line (line 8).
  • Add an [[Rcpp::export]] decorator so that the function is exported to R.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

#include 
using namespace Rcpp ; 

// Export the function to R

double twice(double x) {
    // Fix the syntax error
    return x + x
}
Edit dan Jalankan Kode