Skip to content
Prev 387249 / 398502 Next

Read

This gets it into a data frame. If you know which columns should be numeric you can convert them.

s <- 
"x1  x2  x3 x4
1 B22
2         C33
322 B22      D34
4                 D44
51         D53
60 D62            
"

tc <- textConnection( s )
lns <- readLines(tc)
close(tc)
if ( "" == lns[ length( lns ) ] )
  lns <- lns[ -length( lns ) ]

L <- strsplit( lns, " +" )
m <- do.call( rbind, lapply( L[-1], function(v) if (length(v)<length(L[[1]])) c( v, rep(NA, length(L[[1]]) - length(v) ) ) else v ) )
colnames( m ) <- L[[1]]
result <- as.data.frame( m, stringsAsFactors = FALSE )
result
On February 22, 2021 4:42:57 PM PST, Val <valkremk at gmail.com> wrote:
-- 
Sent from my phone. Please excuse my brevity.