R_uu读取表:分隔符
我想读这个文本文件 该文件的内容如下所示R_uu读取表:分隔符,r,text-mining,read.table,R,Text Mining,Read.table,我想读这个文本文件 该文件的内容如下所示 2013-08-13 19:26:58 Method for modifying a piece of 3D geometry 2013-08-13 19:26:57 Method of interactively modifying a feature ... 我想在这张桌子上读这个文件 dateTime Method "2013-08-13 19:26:58" "Method for modifying a piece of 3D geomet
2013-08-13 19:26:58 Method for modifying a piece of 3D geometry
2013-08-13 19:26:57 Method of interactively modifying a feature
...
我想在这张桌子上读这个文件
dateTime Method
"2013-08-13 19:26:58" "Method for modifying a piece of 3D geometry"
"2013-08-13 19:26:57" "Method of interactively modifying a feature"
...
如您所见,我想用两个连续的空格(“\s\s”)而不是一个空格分隔行
我该怎么做
我尝试使用read.table函数,但分隔符允许使用一个字符
或者我可以在没有第一列的情况下读取文件内容吗
像这样
"Method for modifying a piece of 3D geometry"
"Method of interactively modifying a feature"
请给我一些建议。谢谢请先用任何sep字符替换双空格:
txt<-"2013-08-13 19:26:58 Method for modifying a piece of 3D geometry
2013-08-13 19:26:57 Method of interactively modifying a feature"
read.table(sep="|",text=gsub(" ","|",txt), header=F)
# V1 V2
#1 2013-08-13 19:26:58 Method for modifying a piece of 3D geometry
#2 2013-08-13 19:26:57 Method of interactively modifying a feature
txt只需先用任何sep字符替换双空格:
txt<-"2013-08-13 19:26:58 Method for modifying a piece of 3D geometry
2013-08-13 19:26:57 Method of interactively modifying a feature"
read.table(sep="|",text=gsub(" ","|",txt), header=F)
# V1 V2
#1 2013-08-13 19:26:58 Method for modifying a piece of 3D geometry
#2 2013-08-13 19:26:57 Method of interactively modifying a feature
txt假设您的数据文件位于test.txt
:
txt <- readLines('test.txt')
do.call(rbind, strsplit(txt, ' '))
# or alternatively
do.call(rbind.data.frame, strsplit(txt, ' '))
txt假设您的数据文件位于test.txt
:
txt <- readLines('test.txt')
do.call(rbind, strsplit(txt, ' '))
# or alternatively
do.call(rbind.data.frame, strsplit(txt, ' '))
txt