问题标签 [rbind]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
669 浏览

r - rbind 的效率

我正在编写一个必须构建一个大型矩阵的脚本。我想为每个名称取一个名称向量从不同的数据框中获取数据对其进行一些操作,然后返回该名称的数据向量。例如:

名称列表的长度在 10000 范围内,每个名称 tmpdata 有 1-5 行。我在我的实验室 linux 服务器上运行我的代码,大约 8 GB 内存,
不知何故,我觉得这比它应该花费的时间要长得多,需要几分钟。我怎样才能更有效地做到这一点?

0 投票
4 回答
35037 浏览

r - 在数据框中的特定位置添加新行

这是我的数据:

我想在第四行添加 1 行,如下所示:

我试过像这样使用 rbind() :

但我无法添加到我想要的地方。对于这个问题,我将不胜感激。非常感谢。

0 投票
1 回答
965 浏览

r - Rbind 在 NextMethod() 中抛出错误:无效值

我的数据框如下:

当我尝试执行 rbind 时,出现以下错误

但是当我尝试直接重新创建数据框时,我没有收到该错误:

谁能帮我弄清楚发生了什么以及如何避免这个错误。谢谢。

0 投票
2 回答
5836 浏览

r - 在 R 中使用 rbind.fill 时保留行名

有谁知道如何在rbind.fill函数中保留行名。

我正在设置一个循环,其中对象将使用rbind.fill. 现在我正在使用这样的组合功能:

我想可能有更好的方法。谢谢!

0 投票
4 回答
4043 浏览

r - 不同长度的 rbind 向量:用零(或 NA)填充而不是循环

假设我有两个向量v1v2并且我想调用rbind(v1, v2). 但是,假设length(v1)> length(v2)。从我读到的文档中,较短的向量将被回收。这是这种“回收”的一个例子:

  1. 有什么直接的方法可以阻止我v2被回收,而是将剩余的条目设为 0?
  2. 有没有更好的方法来构建向量和矩阵?

非常感谢所有帮助!

0 投票
2 回答
1048 浏览

r - 嵌套列表到单个表(按列名合并?)

我有一个看起来像这样的嵌套列表:

我想要的是将这些数据加入到具有三列“物种”、“x”和“y”的单个表中(每行都标有可能重复的物种名称,后跟 x,y 坐标)。Cbind 将二阶列表放在彼此相邻的列中,因此我最终得到的列数等于一阶对象数的 3*。Rbind 将二阶列表放入行中,这样我最终得到的列数等于二阶列表的长度。有什么建议么?

0 投票
2 回答
129 浏览

arrays - lapply 和 rbind 没有正确附加结果

当我用 in 循环运行所有命令时,除了最后一个,我得到不同的行列式值,但是当我一次运行循环代码时,我得到所有重复的行列式的最后一个值。

请帮助和指导以控制这样的所有情况。

有没有办法为这段代码提供简短有效的方法,以便也可以访问每个单独的变量。

0 投票
1 回答
529 浏览

r - Creating a function to split data frames multiple times then recombine

I'm working on a large dataset in R with 3 factors: FY (6 levels), Region (10 levels), and Service (24 levels). I need to sum my numeric vector, SumOfUnits, at all three levels, and the only way I can think to do this is to split the data frames up into first: 6 data frames, split by FY, then split those 6 into 10 data frames, split on region, then those 10 into the 24 Services, then I can finally take the sum of the numeric vector and recombine all of the data frames into one. This data frame would then have 6*10*24 (1440) rows and 4 columns. The way I'm currently doing it involves a lot of splitting, so I thought there might be a function I could write that I could use at each level of the split, but I haven't used "function" very much in R so I'm not sure what to write (if there even is something). I also imagine there is probably a more efficient way to get the formatted data set, so I welcome all suggestions.

Here are a few lines from my data frame:

This is the code I've been using for my splits:

I would want a sample of my data to look something like this:

0 投票
7 回答
40009 浏览

r - 如何 rbind 匹配其列名的向量?

rbind 在将向量绑定在一起时不检查列名:

如何从多个列表元素中生成此矩阵,以确保列名跨行正确匹配:

0 投票
1 回答
57 浏览

r - 当R中的特征相同时如何将行组合在一起

我有以下数据

当 X 相同时,我想得到一个将 Y 列组合在一个单元格中的结果。当Z=2时,Y在YY的前面,当z=1时,Y在后面。

结果会是这样

怎么做?谢谢!