r - 如何使用 R 和旋转更长的功能将其正确排列成两两?
问题描述
数据集是
structure(list(`total first - yes RS` = 138L, `total first - no RS` = 29L,
`total second- yes rs` = 6L, `total second- no rs` = 0L), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"))
看起来像
total first -yes RS|total first -no RS|total second -yes rs|total second -no rs
76 20 12 0
我想做的是在我拥有的地方创建一个两个两个
total first| total second
Yes rs 76 12
No rs 20 0
解决方案
这是另一种选择,但具有基本 R 功能reshape
subset(reshape(
cbind(q = "",
setNames(df, tolower(
gsub("\\s?-\\s?", ".", names(df))
))),
direction = "long",
idvar = "q",
varying = -1
),
select = -c(q, time))
这使
total first total second
.yes rs 138 6
.no rs 29 0
推荐阅读
- python-2.7 - Python:for循环覆盖循环中创建的lambda函数
- java - 如何获取通知意图数据
- python - spacy 无法运行并出现错误:“cymem.cymem”没有属性“PyMalloc”
- sql - SQL Server 2012 输出到 txt 文件是在字符串末尾添加空格
- c++ - gSOAP:不完整类型“struct SOAP_ENV__Header”的无效使用
- maven - 是否可以在没有 Maven 的情况下创建 html Cucumber Report
- php - Apache 虚拟服务器 wordpress
- docker - `docker logs` vs `docker container logs`
- asp.net-mvc - @: in a foreach loop doesn't work when it's between tags?
- apache - Directus api 和应用程序与前端在同一台服务器上