는 R 함수 (C++)에 배열 송신 :내가 ++ C이 함수를 작성한
extern "C"
{
void add(int* first, int* second, int *n , int* sum)
{
for (int i = 0; i< *n; i++)
{
sum[i] = first[i] + second[i];
}
}
}
이 드라이버 :
add <- function(twoColumn)
{
if(!is.data.frame(twoColumn))stop("twoColumn should be data.frame")
first <- twoColumn[1]
second <- twoColumn[2]
n <- length(first)
.C("add",first = as.integer(unlist(first)),second = as.integer(unlist(second)), n = as.integer(n),sum = as.integer(rep(0,n)))$sum
}
그러나 R내는 것은 단지 수이고 데이터 프레임의 첫 번째 행의 합계.
아마도 n <- nrow (first)가 도움이됩니까? – Julius
길이 란 무엇입니까? 또한'twoColumn [[1]]'등을 시도하고 unlist를 생략하면'n'은 이미 정수이기 때문에'sum.integer (n)'은 필요 없다. 'rep ... '. –