【发布时间】:2020-10-12 18:31:10
【问题描述】:
我正在使用长表,但需要将其(部分)转换为宽表以使用 Vegan 统计包中的数据。但是,当我使用 pivot-wider 函数时,所有列都以字符结尾。我找不到如何将列(以科学物种名称作为标题)转换为整数的解决方案。我已经阅读了很多帖子,但到目前为止所有解决方案都不起作用。我用来创建表格的代码:
biota_C <- (biota_species) %>%
ungroup() %>%
select(Species, Station, Numbers) %>%
pivot_wider(names_from = Station, values_from = Numbers) %>%
t() %>%
row_to_names(row_number = 1)
除了数据类型之外,结果表对我来说看起来不错。Species table
> glimpse(biota_C)
chr [1:306, 1:27] "0" "1" "0" " 0" " 1" " 2" "1" "2" "0" "4" "0" "0" "0" "0" "0" "3" "0" "1" "0" "0" "0" " 0" ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:306] "X00A2" "X00A4" "X00A6" "X00B2" ...
..$ : chr [1:27] "Aphelochaeta marioni" "Arenicola marine" "Aricidea minuta" "Bathyporeia saris" ...
显然我忽略了一些东西。
最好的,贝瑞
【问题讨论】:
标签: r dplyr type-conversion integer character