Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从子程序输出到R中获取矩形Fortran数组?_R_Fortran - Fatal编程技术网

从子程序输出到R中获取矩形Fortran数组?

从子程序输出到R中获取矩形Fortran数组?,r,fortran,R,Fortran,这是我们的后续行动。不同的是,我想得到一个二维数组,而不是一维数组 我有以下Fortran子程序: subroutine test(d, i, nMCd, DF, X) integer, intent(in) :: d, i, nMCd double precision, intent(in), dimension(i,nMCd) :: DF double precision, intent(out)

这是我们的后续行动。不同的是,我想得到一个二维数组,而不是一维数组

我有以下Fortran子程序:

subroutine test(d, i, nMCd, DF, X)
    integer, intent(in)                                 :: d, i, nMCd
    double precision, intent(in), dimension(i,nMCd)     :: DF
    double precision, intent(out), dimension(i,nMCd)    :: X

    X = DF + DF

end subroutine test
在R中,代码很简单:

input <- data.frame(A=c(11,12), B=c(21, 22))
input + input

谢谢

我查看了
.Fortran
.Call
和“编写R扩展名”的文档,没有发现任何Fortran子例程返回矩阵的实例。此外,
?.Fortran
帮助页中没有矩阵类型,因此我认为我的评论可能是最好的解决方案:

in R you can also coerce a vector to matrix by adding a dimension: dim(X) <- c(2,2).     

Or even with more generality: dim(X) <- dim(input)

在R中,您还可以通过添加维度将向量强制转换为矩阵:dim(X)在R中,您还可以通过添加维度将向量强制转换为矩阵:
dim(X),或者更一般地说:
dim(X)
matrix(X,nrow = nrow(input),ncol = ncol(input))
in R you can also coerce a vector to matrix by adding a dimension: dim(X) <- c(2,2).     

Or even with more generality: dim(X) <- dim(input)