Semplice ricerca su google restituita. ha funzionato perfettamente per me.
> x <- readLines(textConnection("1
+ Pietje
+ I1 I2 Value
+ 1 1 0.11
+ 1 2 0.12
+ 2 1 0.21
+
+ 2
+ Jantje
+ I1 I2 I3 Value
+ 1 1 1 0.111
+ 3 3 3 0.333"))
> closeAllConnections()
> start <- grep("^[[:digit:]]+$", x)
> mark <- vector('integer', length(x))
> mark[start] <- 1
> # determine limits of each table
> mark <- cumsum(mark)
> # split the data for reading
> df <- lapply(split(x, mark), function(.data){
+ .input <- read.table(textConnection(.data), skip=2, header=TRUE)
+ attr(.input, 'name') <- .data[2] # save the name
+ .input
+ })
> # rename the list
> names(df) <- sapply(df, attr, 'name')
> df
$Pietje
I1 I2 Value
1 1 1 0.11
2 1 2 0.12
3 2 1 0.21
$Jantje
I1 I2 I3 Value
1 1 1 1 0.111
2 3 3 3 0.333
Source.
Ok, grazie. Quindi ho letto tutto con 'lines <- scan (inFile, what =" character ", sep =" \ n ")'. La prima tabella ha il titolo sulla prima riga e l'intestazione nella prima riga e il row.names nella prima colonna. La parte dati della tabella è sempre lunga 32 righe. Come faccio ad afferrare quel primo tavolo? – James
Avrei usato readLines (perché so cosa otterrò) e poi usato i segmenti come input: es. 'Read.table (textConnection (linee [02:33])' –