Reputation: 199
I want to read the text file.
contents of file are like below.
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
...
I want to read this file on like this table
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"
...
As you see, I want to separate the line with two consecutive white spaces ("\s\s") not one white space.
How can i do this?
I tried to use read.table function, But the one character is allowed for separator.
Or can i read the file contents without first column?
like this.
"Method for modifying a piece of 3D geometry"
"Method of interactively modifying a feature"
Please give me some advices. Thank you
Upvotes: 0
Views: 1209
Reputation: 5776
Assuming your data file is in test.txt
:
txt <- readLines('test.txt')
do.call(rbind, strsplit(txt, ' '))
# or alternatively
do.call(rbind.data.frame, strsplit(txt, ' '))
Upvotes: 1
Reputation: 8701
Just replace the double space with any sep character first:
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
Upvotes: 3