Reputation: 7517
I know if I copy the content of the object block
and paste it onto a text editor (e.g., notepad), then I can read the block.txt
file as a table in R
like so: read.table('block.txt', header = TRUE)
.
But is there a way to directly (without first creating a block.txt
file) read the block
itself in R
?
block <- "Item1 Item2 Item3
22 52 16
42 33 24
44 8 19
52 47 18
45 43 34
37 32 39"
Upvotes: 0
Views: 52
Reputation: 887951
We can use fread
library(data.table)
fread(block)
# Item1 Item2 Item3
#1: 22 52 16
#2: 42 33 24
#3: 44 8 19
#4: 52 47 18
#5: 45 43 34
#6: 37 32 39
Upvotes: 0
Reputation: 389325
You can specify block
as text
argument of read.table
:
read.table(text = block, header = TRUE)
# Item1 Item2 Item3
#1 22 52 16
#2 42 33 24
#3 44 8 19
#4 52 47 18
#5 45 43 34
#6 37 32 39
Upvotes: 1