Here would be my way to do it: call read.table
with the option fill=TRUE
, and exclude the lines without all fields filled afterward (with a call to count.fields
).
Example:
# 1. Data generation, and saving in 'tempfile'
cat("1 John", "2 Paul", "7 Pierre", '9', file = "tempfile", sep = "\n")
# 2. read the data:
data = read.table('tempfile',fill=T)
# 3. exclude incomplete data
c.fields = count.fields('tempfile')
data = data[ - (which(c.fields) != max(c.fields)),]
(edited to get automatically the number of rows)