- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,晚上好,来自德国:)
我对 R 很陌生,但我真的处于我的理解极限。
基本上我有 n 个矩阵,它们在一个列表中。它们看起来像这样:
$edu
cue op split pred
1 edu < 1 TRUE
2 edu > 1 TRUE
3 edu == 1 TRUE
4 edu < 2 TRUE
5 edu > 2 TRUE
6 edu == 2 TRUE
7 edu < 3 TRUE
8 edu > 3 TRUE
9 edu == 3 TRUE
$religion
cue op split pred
1 religion == 0 TRUE
2 religion == 1 TRUE
3 religion == 0 FALSE
4 religion == 1 FALSE
$med_exp
cue op split pred
1 med_exp == 0 TRUE
2 med_exp == 1 TRUE
3 med_exp == 0 FALSE
4 med_exp == 1 FALSE
cue op split pred cue op split pred cue op split pred
edu < 1 TRUE religion == 0 TRUE med_exp == 0 TRUE
edu < 1 TRUE religion == 0 TRUE med_exp == 1 TRUE
edu < 1 TRUE religion == 0 TRUE med_exp == 0 FALSE
edu < 1 TRUE religion == 0 TRUE med_exp == 1 FALSE
[..]
med_exp == 0 TRUE edu < 1 TRUE religion == 0 TRUE
structure(list(edu = structure(list(cue = structure(c(1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L), .Label = "edu", class = "factor"), op = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("<", ">", "=="), class = "factor"),
split = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L,
1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L), pred = c(TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE)), .Names = c("cue", "op", "split",
"pred"), out.attrs = structure(list(dim = c(1L, 3L, 4L, 2L),
dimnames = structure(list(Var1 = "Var1=edu", Var2 = c("Var2=<",
"Var2=>", "Var2==="), Var3 = c("Var3=1", "Var3=2", "Var3=3",
"Var3=4"), Var4 = c("Var4=TRUE", "Var4=FALSE")), .Names = c("Var1",
"Var2", "Var3", "Var4"))), .Names = c("dim", "dimnames")), class = "data.frame", row.names = c(NA,
-24L)), edu_hus = structure(list(cue = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L), .Label = "edu_hus", class = "factor"), op = structure(c(1L,
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L,
3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("<", ">", "=="), class = "factor"),
split = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L,
1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L), pred = c(TRUE,
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE)), .Names = c("cue", "op", "split",
"pred"), out.attrs = structure(list(dim = c(1L, 3L, 4L, 2L),
dimnames = structure(list(Var1 = "Var1=edu_hus", Var2 = c("Var2=<",
"Var2=>", "Var2==="), Var3 = c("Var3=1", "Var3=2", "Var3=3",
"Var3=4"), Var4 = c("Var4=TRUE", "Var4=FALSE")), .Names = c("Var1",
"Var2", "Var3", "Var4"))), .Names = c("dim", "dimnames")), class = "data.frame", row.names = c(NA,
-24L)), religion = structure(list(cue = structure(c(1L, 1L, 1L,
1L), .Label = "religion", class = "factor"), op = structure(c(1L,
1L, 1L, 1L), .Label = "==", class = "factor"), split = c(0L,
1L, 0L, 1L), pred = c(TRUE, TRUE, FALSE, FALSE)), .Names = c("cue",
"op", "split", "pred"), out.attrs = structure(list(dim = c(1L,
1L, 2L, 2L), dimnames = structure(list(Var1 = "Var1=religion",
Var2 = "Var2===", Var3 = c("Var3=0", "Var3=1"), Var4 = c("Var4=TRUE",
"Var4=FALSE")), .Names = c("Var1", "Var2", "Var3", "Var4"
))), .Names = c("dim", "dimnames")), class = "data.frame", row.names = c(NA,
-4L))), .Names = c("edu", "edu_hus", "religion"))
最佳答案
注意dput
提供的数据与之前显示的不一样。此外,列表的元素是 data.frames 而不是矩阵。前者是有道理的,因为您混合了不同类型(因子、整数、逻辑数),而矩阵只能包含一种类型。因此,我在这里给出的代码也返回一个 data.frame。您可以随时使用 as.matrix
关于它,但我建议不要在大多数情况下这样做。
#create combinations of row indices
ind <- expand.grid(seq_len(nrow(dat[[3]])),
seq_len(nrow(dat[[2]])),
seq_len(nrow(dat[[1]])))
#use subsetting and cbind
res <- cbind(dat[[1]][ind[,3],],
dat[[2]][ind[,2],],
dat[[3]][ind[,1],])
head(res)
# cue op split pred cue op split pred cue op split pred
# 1 edu < 1 TRUE edu_hus < 1 TRUE religion == 0 TRUE
# 1.1 edu < 1 TRUE edu_hus < 1 TRUE religion == 1 TRUE
# 1.2 edu < 1 TRUE edu_hus < 1 TRUE religion == 0 FALSE
# 1.3 edu < 1 TRUE edu_hus < 1 TRUE religion == 1 FALSE
# 1.4 edu < 1 TRUE edu_hus > 1 TRUE religion == 0 TRUE
# 1.5 edu < 1 TRUE edu_hus > 1 TRUE religion == 1 TRUE
lapply
和
do.call
概括该方法:
sl <- lapply(dat, function(df) seq_len(nrow(df)))
sl <- sl[rev(seq_along(sl))]
ind <- do.call(expand.grid, sl)
ind <- ind[,rev(seq_along(dat))]
res <- do.call(cbind, lapply(seq_along(dat), function(i) dat[[i]][ind[,i],]))
关于r - expand.grid 与现有 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18577905/
我有一个简单的 Card 组件,是从material-ui 的网站复制的。 我正在尝试在我的代码中实现它。当我单击 CardHeader 时,它不会展开。 这是我的组件: import React,
我已经使用延迟加载实现了一棵树。第一级节点是在树创建时创建的,其中只有当用户展开任何特定节点时才会创建子节点。 数据来自数据库,我们向数据库发出查询以填充子节点。实现了 TreeExpansionLi
假设我有 3 个向量(仅作为示例)。现在我想获取这 3 个所有可能组合的随机样本。通常,我会这样做: x <- 1:3 y <- 10:12 z <- 15:18 N <- length(x) * l
如果我使用 dabbrev-expand为了扩展,Emacs 搜索当前缓冲区,然后搜索其他具有相同模式的缓冲区。这是由 dabbrev-friend-buffer-function 处理的默认设置为
我想像这样切片主窗口 我的布局代码如下: QGridLayout *gLayout = new QGridLayout (); viewWidget->setStyleSheet("backgroun
我在 Android Studio Canary 1 上尝试 Jetpack Compose 并添加了 Column可组合到 ui。 Column有一个名为 modifier 的属性我们可以在其中传递
我正在努力让我们的 Accordion 可以使用 aria-expanded 等 aria 标签来访问。当单击 Accordion 触发器标题或按下键盘上的“返回”按钮时,我正确地更改了 aria-e
根据 http://doc.qt.io/qt-5/qsizepolicy.html#Policy-enum ,设置小部件的大小策略具有以下效果: The sizeHint() is a sensibl
我将使用Live Actitions显示实时数据,并在一个应用程序中添加对Dynamic Island的支持,该应用程序具有现有的小部件扩展。然而,我也不能把它造出来。当我收到错误信息时。和。即使我提
我有一个设置,如下所示: //With dynamic content here. 我正在运行一个脚本,该脚本将 #nav 的大小调整为浏览器窗口的高度大小。但有时我的
我正在使用jquery checkboxtree plugin它效果很好,并且上面的链接中有很好的文档和示例。我现在遇到一种情况,我想以编程方式检查节点。使用以下语法支持此操作: $('#tabs-
我正在尝试以下实验: 我有两个QpushButtons,比如PushA 和PushB。现在 PushA 在 QHBoxLayout 中,PushB 也在它自己的 QHBoxLayout 中。这两个水平
我目前有一个 OData V4 服务,它具有以下模型。 “类别”——“代码” 对于每个类别,可以有许多代码。 我需要 $expand the Codes, $filter where Active =
我的目的是创建一个带有 QVBoxLayout 的可滚动控件,上面有各种控件(比如按钮)。该控件放在 *.ui 窗体上。在该控件的构造函数中,我编写了以下代码: MyScrollArea::M
你们如何解决以下 Flutter 布局? 我有一个屏幕,我必须在其中显示,如图所示:一个 Logo + 3 个 TextFormFields + 2 个按钮 + 一个容器。 问题: 我需要将所有小部件
我使用最新版本的 mvvm light 工具包,但是我不清楚如何将 EventToCommand 用于事件 TreeViewItem.Expanded。 这很有效......我做错了什么?
我是 LINQ 的新手。 我有以下查询,我不知道它代表什么。 var query = (from p in data.First
这里有一个小问题。我有一个表,当我想单击运行时,该表应该展开,而且同一行中有一个展开按钮,它也应该展开一个 div。 问题:当我单击该行时,一切正常,div 将滑入。当我单击按钮(位于表行中)时,会产
图片:
我的应用程序中有 Expander 设置 FlowDirection 正常工作,但标题文本显示在水平方向。我想显示标题文本垂直绘制。 最佳答案 使用 sl 工具包中的 LayoutTransforme
我是一名优秀的程序员,十分优秀!