- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 data.frame
中有一个数据频率表在 R 中列出因素级别和成功和失败的计数。我想将它从频率表转换为事件列表 - 即与“表”命令相反。具体来说,我想把这个:
factor.A factor.B success.count fail.count
-------- -------- ------------- ----------
0 1 0 2
1 1 2 1
factor.A factor.B result
-------- -------- -------
0 1 0
0 1 0
1 1 1
1 1 1
1 1 0
reshape
应该这样做,或者甚至是我没有听说过的一些晦涩的基本功能,但我没有运气。甚至重复
data.frame
的单个行很棘手 - 如何将可变数量的参数传递给
rbind
?
最佳答案
你可以试试这个:
# create 'result' vector
# repeat 1s and 0s the number of times given in the respective 'count' column
result <- rep(rep(c(1, 0), nrow(df)), unlist(df[ , c("success.count", "fail.count")]))
# repeat each row in df the number of times given by the sum of 'count' columns
data.frame(df[rep(1:nrow(df), rowSums(df[ , c("success.count", "fail.count")]) ), c("factor.A", "factor.B")], result)
# factor.A factor.B result
# 1 0 1 0
# 1.1 0 1 0
# 2 1 1 1
# 2.1 1 1 1
# 2.2 1 1 0
关于r - 从 R 中的频率表创建一个包含单独试验的表(表函数的逆),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822922/
假设您正在对二项式数据进行建模,其中每个响应都是来自带有一些解释变量(a 和 b)的多次试验 (N) 的多次成功 (y)。有几个函数可以做这种事情,它们似乎都使用不同的方法来指定 y 和 N。 在gl
在阅读一本 JavaScript 书时,我读到了 all the attributes of Data Properties defaults to true when "defined direct
为了尝试使用 Firebase 推送通知,我遵循以下示例: https://github.com/firebase/quickstart-ios/blob/dc2cd2db6e82e5c475fa3f
我使用 Javascript 操作 HTML 元素的大部分经验都涉及 innerHTML 属性。当涉及到 DOM 操作时,我的知识严重缺乏。因此,为了尝试纠正这个问题,我一直在试验 Javascrip
我的 react 组件有一个文件输入(上传)元素。当用户上传一个xlsx文件时,一个组件方法被调用,该方法读取xlsx文件并转换成JSON并放入redux表中。该方法是接受文件的“convertFil
我已经根据我在网上找到的一些教程编写了一组简单的 SSL 客户端/服务器程序 - 这些程序工作正常。我无法理解的是事物的客户端(见下文) 从代码看来,客户端连接到 SSL 服务器,盲目地接受它提供的证
需要明确一个关于redis EXPIRE操作的概念。 假设我写了下面的代码: HMSET myself name "Sam" age "21" EXPIRE myself 60 这会设置散列 my
我们希望通过 Stripe Subscriptions 支持的付款方式免费试用我们的产品。 但是,我不确定是否可以通过将用户限制为一次刷卡试用来防止用户收到多封电子邮件,类似于 Netflix 等网站
正在观看 David beazley 的( http://www.dabeaz.com ) video about python threads ,我正在尝试线程的东西 def countdown(n
这是我正在处理的玩具项目的当前主屏幕(后面是 .xml): 我得到了我想要的布局,但我的布局是否合理?有没有更好的方法可
我正在尝试重现来自 http://twistedmatrix.com/documents/current/core/howto/trial.html 的“使用 Twisted 进行测试驱动开发”的示例
我一直在使用 RV32I 和 RV64I 汇编器在 RiscV 上测试以下代码。 汇编源文件是 .text slli x31,x31,63 当我针对 32 位目标进行汇编时,我获得以下机器代码输出
我是一名优秀的程序员,十分优秀!