r - 一种读取数据表的方法
问题描述
我正在寻找一种方法,可以将这些文本行读入 df 列中,以便我可以在上面练习。
some text sample 1
some text sample 2 3
some more text 's sample here and then
another one
How to add text to df using read.table
输出:
text
1 some text sample 1
2 some text sample 2 3
3 some more text 's sample here and then
4 another one
5 How to add text to df using read.table
谢谢你帮助我。
解决方案
我们可以使用readLines
读取每一行然后转换为data.frame
. 通过这种方式,我们可以确定它将读取一行作为一个整体,并且不依赖于任何分隔(如果存在)
data.frame(text = readLines('file.txt'))
# text
#1 some text sample 1
#2 some text sample 2 3
#3 some more text 's sample here and then
#4 another one
#5 How to add text to df using read.table
我们也可以使用read.table
不同的sep
df <- read.table('file.txt', header = FALSE, col.names = 'txt', sep=",")
推荐阅读
- python - 想使用 Groupby 查找 Year on Year 计算并申请不同年份
- python - 尝试使用 selenium 获取 html 元素时出错
- arrays - Highchart 系列数据值 Double 数组
- mysql - 使用 JPA/Native 查询在 MySql 中进行批量/批量搜索
- python - 如何在 Python 中保存修改后的书架?
- docker - docker-compose elasticsearch和golang连接被拒绝
- python - 在 tkinter python 中一次加载一个目录中的图像
- arrays - 将字符串读入C中的二维字符串数组
- python - 在 Python 中阅读主题并计算大小写字母
- c++ - 我遇到一个问题,Struct identifier is undefined and incompatible declarations for functions on AVL tree program