Question

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

Was it helpful?

Solution

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

OTHER TIPS

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, '  '))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top