小编Dan*_*anO的帖子

对于基础 R 或 tidyverse 中的多维数组,是否有 reshape2::melt 的替代方案?

g假设我有一个维度为 的3 维数组[x,y,z]reshape2::melt(g)将生成一个数据框,其中的列给出索引x,y,zvalue其中value包含先前数组的每个条目中的值。

鉴于它reshape2被取代,是否有一个“单一功能”替代reshape2::melt基础 R 的功能或tidyverse我缺少的更积极支持的包?

reshape2建议人们使用tidyr,但我似乎无法在tidyr. 有cubylr,但最近似乎也不是很活跃。

我可以编写一个自定义解决方案,只是寻找一些稳定且功能简单的解决方案reshape2::melt来解决此类问题

library(reshape2)

g_as_array <- array(rnorm(9), dim = c(3,3,3)) # create a 3D array

g_as_data_frame <- reshape2::melt(g_as_array) # melt down to "tidy" format

head(g_as_data_frame)
#>   Var1 Var2 Var3      value
#> 1    1    1    1  1.4092362
#> 2    2    1    1 -2.1606972
#> 3    3    1 …
Run Code Online (Sandbox Code Playgroud)

arrays r reshape2 tidyr

7
推荐指数
2
解决办法
663
查看次数

你如何将类 Eigen::MatrixXd 的对象转换为类 Rcpp::NumericMatrix

我正在开发一个需要一些非常快速的矩阵乘法的包,所以希望使用RcppEigen. 出于各种原因,尽管与多维数组的需要有关,但我需要将类 Eigen::MatrixXd 的创建对象转换为类 Rcpp::NumericMatrix。

我尝试反转 RcppEigen::FastLm.cpp 中列出的步骤,但这似乎不起作用

例如而不是使用

const Map<MatrixXd> X(as<Map<MatrixXd> >(Xs));

我试过

Rcpp:NumericMatrix X(as<Rcpp::NumericMatrix>(Xs));

其中 Xs 是 Eigen::MatrixXd 类的矩阵,但这似乎不起作用:“错误:没有匹配函数调用 'as' return Rcpp::asRcpp::NumericMatrix(z);”

如果这根本不可能,我可以尝试另一个方向。

基本上我需要在 R 语言中做的是

a = matrix(1, nrow = 10, ncol = 10)

b = array(0, c(10,10,10))

b[,,1] = a

Run Code Online (Sandbox Code Playgroud)

给出一个更清晰的起始示例

我将如何将 MatrixXd 类的对象存储在 NumericMatrix 类的对象中?

a = matrix(1, nrow = 10, ncol = 10)

b = array(0, c(10,10,10))

b[,,1] = a

Run Code Online (Sandbox Code Playgroud)

r rcpp eigen

5
推荐指数
1
解决办法
147
查看次数

在 macOS 上更新 gdal 后安装 R 包 sf 0.9.0 时出错

我已经sfrprojMac上工作,直到永远,因为还是升级到卡塔利娜/ R 3.6.2工作。

我尝试sf从 CRAN 和开发版本中安装最新版本的(0.9.0),但两种方式都出现错误,configure: error: libproj not found in standard or given locations.

我已经检查并删除了计算机上 gdal 和 proj 的最后痕迹,卸载了两者,重新安装,但仍然是同样的问题。现在,尝试安装sf我知道在我的计算机上工作的旧版本(0.8.1) 也失败了。完全被这里难住了!

GDAL 2.4.4,2020/01/08 发布

R v3.6.2

macOS 10.15.3

configure: CC: clang
configure: CXX: clang++ -std=gnu++11
checking for gdal-config... /usr/local/bin/gdal-config
checking gdal-config usability... yes
configure: GDAL: 2.4.4
checking GDAL version >= 2.0.1... yes
checking for gcc... clang
checking whether the C compiler works... yes
checking for C compiler default output file name... …
Run Code Online (Sandbox Code Playgroud)

macos r gdal rgdal r-sf

4
推荐指数
1
解决办法
934
查看次数

标签 统计

r ×3

arrays ×1

eigen ×1

gdal ×1

macos ×1

r-sf ×1

rcpp ×1

reshape2 ×1

rgdal ×1

tidyr ×1