作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个问题在这里已经有了答案:
Converting multiple boolean columns to single factor column
(4 个回答)
2年前关闭。
尝试将具有多个 bool 列的数据框融合或折叠到具有 id 列和折叠值列的两列数据库中,但每个值都会产生一个新行。
示例开头:
A S1 S2 S3 S4
1 ex1 1 0 0 0
2 ex2 0 1 0 0
3 ex3 0 0 1 0
4 ex4 1 1 0 0
5 ex5 0 1 0 1
6 ex6 0 1 0 0
7 ex7 1 1 1 0
8 ex8 0 1 1 0
9 ex9 0 0 1 0
10 ex10 1 0 0 0
A Type
ex1 S1
ex2 S2
ex3 S3
ex4 S1
ex4 S2
ex5 S2
ex5 S4
ex6 S2
ex7 S1
ex7 S2
ex7 S3
ex8 S2
ex8 S3
ex9 S3
ex10 S1
最佳答案
在基础 R 中:
subset(cbind(A=dat[,1],stack(dat[-1])),values==1,-2)
A ind
1 ex1 S1
4 ex4 S1
7 ex7 S1
10 ex10 S1
12 ex2 S2
14 ex4 S2
15 ex5 S2
16 ex6 S2
17 ex7 S2
18 ex8 S2
23 ex3 S3
27 ex7 S3
28 ex8 S3
29 ex9 S3
35 ex5 S4
library(tidyverse)
dat%>%
gather(Type,j,-A)%>%
filter(j==1)%>%
select(-j)
A Type
1 ex1 S1
2 ex4 S1
3 ex7 S1
4 ex10 S1
5 ex2 S2
6 ex4 S2
7 ex5 S2
8 ex6 S2
9 ex7 S2
10 ex8 S2
11 ex3 S3
12 ex7 S3
13 ex8 S3
14 ex9 S3
15 ex5 S4
关于R:将多个 bool 列折叠为单个属性列,每个组合都有新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51092121/
我正在使用 Apache wicket 创建我的第一个应用程序,但遇到了一个问题。用户通过身份验证方法登录后,我有一个为该用户创建的新 session 。现在,如果我想只为该用户存储数据,我将如何使用
我是一名优秀的程序员,十分优秀!