The "trick" is a text join as the argument to "file" for read.table:
dat <- read.table(textConnection("person1 12 15 person2 15 18 person3 20 14"), stringsAsFactors=FALSE ) str(dat) 'data.frame': 3 obs. of 3 variables: $ V1: chr "person1" "person2" "person3" $ V2: int 12 15 20 $ V3: int 15 18 14
The "sep" argument works by default to separate spaces. If you need tabs for highlighting, use sep = "\ t" (after closing with a call to textConnection ).
Edit: this is actually included in a subsequent revision of the base scan function that was given the "text" argument. Now the code may simply be:
dat <- read.table(text="person1 12 15 person2 15 18 person3 20 14", stringsAsFactors=FALSE )
The readLines function still requires the use of textConnection to read from a "character" object, since it does not use scan .
source share