精華區beta R_Language 關於我們 聯絡資訊
※ 引述《gsuper (Logit(odds))》之銘言: : cppFunction( : ' : int fx(NumericVector x) : { int ss = x.size(); : return ss; : } : ' : ) : --------------- : 在上述的 function 中 : 1.NumericVector : 是否是 Rcpp 提供的特殊變數宣告方式? : 還是這是正常的 C語言 之宣告? : [SEXP object] : Integer(Vector|Matrix) ; integer vectors and matrices : Numeric(Vector|Matrix) ; numeric : Logical(Vector|Matrix) ; logical : Character(Vector|Matrix) ; character : Raw(Vector|Matrix) ; raw : Complex(Vector|Matrix) ; complex : GenericVector ; list : -------------- short answer: 是 long answer: 這些類別是Rcpp利用C++的物件導向特性, 利用RAII: http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization 的技術,將建立R 物件相關的C API所封裝而成的類別 所以的確是Rcpp提供的變數宣告方式。 : 2. x.size() : 這是類似 size(x) 的感覺 : 請問 size() 是 C 的 function 還是 R 的? short answer: 是Rcpp的 long answer: size這個「方法」是Rcpp模仿c++ STL: http://en.wikipedia.org/wiki/Standard_Template_Library 風格建立的方法, 所以只要include<Rcpp>就有了 Rcpp是刻意要遵循STL 的風格,這樣才可以直接套用許多STL 的演算法,如: NumericVector x = ...; std::sort(x.begin(), x.end()); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.81.76.108 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1422452280.A.1CF.html ※ 編輯: Wush978 (111.81.76.108), 01/28/2015 21:39:06
ee012345: 推一個精闢解釋 01/31 02:27
gsuper: 將像之前的一串貢丸與一盒貢丸解釋 vector 與 matrix 啦 01/31 03:44
gsuper: 就 01/31 03:44