Skip to content
Prev 312476 / 398506 Next

how to separate stuck row elements?

On 30-11-2012, at 13:55, Jaime Otero Villar wrote:

            
Taking into account your description simulate file.
Use readLines to read the file into a vector of lines.
Use gsub() to replace each - with a single space.
Finally use read.table to get a dataframe.


# use the example consisting of 3 lines
data.text <- "-100 -100-3456-3456-3456-100 -100
23 -3456-3456-189 34 56 78
-100 34 56 21 44 65 78"

x.lines <- readLines(textConnection(data.text))
x.lines

# replace - with single space 
 
x.1 <- gsub("-"," ",x.lines)
x.1

read.table(text=x.1, header=FALSE) 

Berend