- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
例如,我有一个这样的 tibble。
测试 <- tibble(a = 10, b = "a")
有了这个输入,我想要一个可以返回代表 double 和字符的“dc”的函数。
我问这个的原因是我想读很多文件。我不想让 read_table 函数来决定每列的类型。我可以手动指定字符串,但由于我要导入的实际数据有 50 列,因此手动操作非常困难。
谢谢。
最佳答案
而前面提到的test %>% summarise_all(class)
将以长格式为您提供列的类名,而在此问题中,您将它们转换为对 read_table
有意义的单字符代码。 col_types
.要将类名映射到单字母代码,您可以使用查找表,这是一个(不完整的)示例,带有 dput
:
structure(list(col_type = c("character", "integer", "numeric",
"double", "logical"), code = c("c", "i", "n", "d", "l")), .Names = c("col_type",
"code"), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-5L))
types
,我们最终可以在单个字符串中转换列类型:
library(dplyr)
library(tidyr)
library(stringr)
test %>%
summarise_all(class) %>%
gather(col_name, col_type) %>%
left_join(types) %>%
summarise(col_types = str_c(code, collapse = "")) %>%
unlist(use.names = FALSE)
summarise_all
),然后将它们收集到一个匹配列名称与列类型 (
gather
) 的小标题中。
left_join
匹配
col_type
column 并为每个列名称提供简短的 1-char 代码。现在我们不对列名做任何事情,所以只需连接
summarise
就可以了。和
str_c
.最后
unlist
把绳子从小东西里拉出来。
关于r - 如何以紧凑的字符串表示形式返回 R tibble 的 col 类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44580837/
问题:用任何语言编写一个程序,给定一个字符串,生成一个与输入字符串的任何字谜匹配的正则表达式。对于所有大于某个长度 N 的正则表达式,正则表达式必须短于列出所有可能的字谜的“蛮力”解决方案,其中列出了
我正在尝试使用 html 和 css 生成一个简单的甘特图,我需要弄清楚如何使它紧凑,这意味着如果有可用的空白,该条应尝试适合前一行,同时保持相同的 x 距离。 上下文: X 轴是以月为单位的时间轴
我收到以下错误 (1/1) ErrorException compact(): Undefined variable: operator 这是我的代码行 $postsCat = Post::w
我正在使用 java 读取紧凑/截断的 PDF417 条形码,并且我有标准 PDF417 条形码的开始和结束模式的矩阵: Start Pattern = 81111113 (ending wit
我正在使用的当前 ListView 在文本上方和下方有额外的空间。我如何使它成为一个真正紧凑的? http://jsfiddle.net/qW6sP/8/
是否有办法“压缩”SQL 查询的结果? 结果如下: +----+-----------+----------+-----------+-------------+--------+ | ID | Fi
我目前在我的 Java 项目中使用 JSON(通过 gzip 压缩),其中我需要在磁盘上存储大量对象(数亿)。我每行有一个 JSON 对象,并且不允许在 JSON 对象中换行。这样我就可以逐行从磁盘流
R具有qr()函数,该函数使用LINPACK或LAPACK执行QR分解(以我的经验,后者快5%)。返回的主要对象是一个矩阵“ qr”,该矩阵包含在上三角矩阵R中(即R=qr[upper.tri(qr)
我希望开始 SQL 开发,因此决定用 Java 和 C# 实现一个使用基于 SQL 的数据库的应用程序,特别是它将是一个桌面应用程序,用于存储某些类型的数据通过数据库访问用户机器。 阅读此处发布的答案
我目前正在尝试解决一个奇怪的问题。我找不到太多相关信息。 简而言之: 当反序列化一个 xml 序列化对象时,我得到了一个正确对象类型的实例,但我只得到了对象内部的默认值。 长话短说: 序列化和反序列化
假设我需要一个包含许多重复元素的数组,如下所示: [3,3,3,3,3,8,8,8,8,5,5,5,5,5,5](所以这是五个 3,四个 8,和六个 5) 在 python 中,你可以像这样非常优雅地
这个问题在这里已经有了答案: Reverse the ordering of words in a string (48 个回答) 关闭 7 年前。 所以我正在尝试针对提示提出一个好的 C++ 解决
我是一名优秀的程序员,十分优秀!