问题标签 [dcast]

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 投票
2 回答
30 浏览

r - 重塑(转换为字符)

我有以下矩阵

我想将其转换为 1 行并将列数加倍

我尝试了以下(as.vector(t(data))). 但是,当我这样做时,它会将所有内容转换为字符,并且我会丢失数据信息

有什么帮助吗?

0 投票
1 回答
112 浏览

r - dcast function taking arguments from two value variables

Say I have an example dataframe with following structure

I now want to apply a reshaping with dcast like

As you can see, function "car_PS_var" is user-defined with two inputs

I do not know how to apply a function which takes the two "value.var" as arguments, and return one. Normally with dcast you can only apply a function to only one variable, thats why car_PS_var("PS_mean", "PS_stdv") does not work

In this form R will throw some errors because it cannot take two inputs in dcast function.

So how can I correctly do that? If you suggest any other R method which does the task, is also fine

0 投票
2 回答
74 浏览

r - 在 R 中操作因子和类别

所以我有一个我正在尝试操作的数据集,但我似乎找不到正确的方法来做到这一点。Iv 研究过使用 dcast 和 spread,但不确定如何进行正确的操作。

所以我有类似的东西:

我希望它看起来像这样:

简单的示例数据

0 投票
2 回答
248 浏览

r - Error when using pander on a data.table created with data.table::dcast

this is more a question of interest, as I found a work-around, although I don't find it pretty.

When I updated the pander package (to 0.6.1) an error started to occure whenever I try to to use pander() on a data.table in wide format that was constructed from a data.table (package version 1.10.4-3 or older) in long format using data.table::dcast():

Error in data.table::setattr(x, "row.names", row.names.dt) : row names must be 'character' or 'integer', not 'double'

I tried to remove any row names, but to no avail. After some research, I found out that with reshape2::dcast there is no error, but reshape2::dcast transforms the data.table in a data.frame, which isn't something I want. Of course I could transform the data.frame back into a data.table.

Here is some sample code that produces the error for me:

Is there a simple way to keep the data as data.table and use pander as it worked before?
I use R version 3.3.2, in case this matters.

Thank you in advance!

0 投票
1 回答
29 浏览

r - R cast 不能处理唯一的行

问题


我有cluster.id并且对应于这些cluster.id,我letters在每个集群中都有不同的发现(作为简化)。

我对通常在不同的集群上一起找到哪些字母感兴趣(我使用了这个答案中的代码),但是我对找到每个字母的比例不感兴趣,所以我想删除重复的行(见代码以下)。

这似乎很有效(没有错误),但是转换矩阵被填充了'NA'字符串而不是所需的计数(我在下面的代码注释中进一步解释了所有内容)。

任何建议如何解决这个问题,或者这只是在过滤唯一行后不可能的事情?

代码


0 投票
1 回答
2424 浏览

r - R - 带有小计的数据透视表

如何在 R 中获取带有小计的数据透视表(如 MS Excel 数据透视表)?

我正在使用dcastfrom package 在 R 中创建枢轴。我还使用andreshape2得到了总计。我承认我不理解参数集中的复杂性。我只知道如何创建数据透视表,帮助文件超出了我的想象。如果有人可以解决这个问题(我怀疑它可以做到这一切),并解释解决方案所需的参数,那将非常有帮助。rowSumscolSumsdcastdcast

我正在使用此代码(C2 有两个因素,X1 和 X2):

我没有得到所有这些边距、子集、填充或删除的作用。帮助文件似乎过于迟钝,我在互联网上也没有得到太多帮助。

样本枢轴(没有小计,T 是总计):

样本预期枢轴(带有小计 t,T 是总计)

0 投票
1 回答
300 浏览

r - R:当超过2维时重塑数据框

我正在尝试将数据框转换为另一个数据框,请参见下面的示例:

我想要一个像这样的数据框:

计算第 1 行是因为我们有 ABC -> 1 和 ABc -> 2 所以 AB -> 3

事实是我可以想象一个在列上有一些 for 循环的解决方案,但我需要它来节省时间,我可以有 100,000 行和多达 100 列,所以我需要一些快速的东西,而且我不认为 for循环在 R 中非常有效。

你有什么想法?

谢谢!

0 投票
2 回答
3682 浏览

r - dcast() value.var 找不到输入

我正在尝试使用dcast(),但我无法弄清楚为什么会出现此错误:

“错误:在输入中找不到 value.var (mpg)”。Dcast 似乎找不到我在 melt 函数中制作的 measure.vars 的“mpg”。

你们能帮帮我吗?

这是我的代码:

0 投票
1 回答
26 浏览

r - 在重塑数据方面需要帮助

我是新来的,也是 R 世界的新手。我一直在尝试重塑数据,但在通过 dcast、melt、reshape 选项后我无法做到。

我的数据看起来像, 原始数据

TESTCODE BATCHNUMBER BATCHVALUE DATALINEID

测试1 100 _83281
测试1 99 _83284
测试1 100 _83287
测试1 101 _83290
测试2 101 _83281
测试2 95 _83284
测试2 99 _83287 _83287
测试2 98 _83290 测试 3
99 _83282328328328328313283831313831383138313838313831383838383838388388388388388383838383838383838383838383838388888888888888888888888888883 ;


它需要转换成这样的东西,

期望的输出

TESTCODE DATALINEID BATCH1 BATCH2 BATCH3

我试过使用 dcast(TEST,TESTCODE+DATALINEID ~., value.var = "BATCHVALUE") ,它给出的输出如下

还有 dcast(TEST, TESTCODE+BATCHNUMBER ~ DATALINEID +., value.var = "BATCHVALUE")

TESTCODE BATCHNUMBER _83281 _83284 _83287 _83290

期待回复,从而学习新的东西。谢谢你。

0 投票
0 回答
63 浏览

r - 具有单个或多个 value.vars 的 data.table::dcast 的输出中的列名不一致

考虑以下 data.table 示例:

如果我们dcast按照帮助页面所示运行:

z正如预期的那样,值列的名称是 value.var 列和 中的值的组合: d1_a, d1_b, d2_a, d2_b

但是,如果我们在 value.var 中只使用一列运行相同的代码:

新值列的名称仅来自 的值z而不是来自d2: a, b

这是一种可以理解的行为,但它与 data.table (1, b) 的 reshape 小插图中给出的示例相矛盾,并且在以dcast编程方式在具有可变数量的包内使用该函数的情况下,value.var这种行为是不希望的。

有没有办法改变这种行为?