r - 将一列中的单词分成一行
问题描述
我想拆分一列中的所有单词,以便它们各占一行(然后其余数据列重复)。
#Example Data
example_words <- c("one two three", "four five", "six")
values <- c(1, 2, 3)
tibble_test <- tibble(example_words, values)
# Expected output
example_words <- c("one", "two", "three", "four", "five", "six")
values <- c(1, 1, 1, 2, 2, 3)
tibble_test <- tibble(example_words, values)
提前致谢
解决方案
这是否有效:
library(dplyr)
library(tidyr)
tibble_test %>% separate_rows(example_words, sep = ' ')
# A tibble: 6 x 2
example_words values
<chr> <dbl>
1 one 1
2 two 1
3 three 1
4 four 2
5 five 2
6 six 3
推荐阅读
- javascript - 似乎无法在循环中应用 classList.toggle
- android - 在 AsyncTask 事件之间使用共享变量
- load-balancing - F5 - A10 负载均衡器迁移
- sql - SQL Server - 分组依据 - 附加列
- java - 锁定一个随机数组,以便可以从其他方法处理它而不会被随机化
- python - Gitlab CI/CD 中的 Tika-OCR python 测试
- r - 如何基于另一列创建具有重复值的新列?
- python - 在 Scrapy Splash 中使用 Crawlera lua 脚本时如何获取 session_id?
- git - 如何在不修改 git 历史记录的情况下在我的源代码上运行代码格式化程序?
- configuration - Spring Cloud Contract 在运行时设置`stubsMode`