I have a large data file consisting of a single line of text. The format resembles
Cat 14 Dog 15 Horse 16
I\'d eventually like to get
This solution takes full advantage of scan()'s what argument, and seems simpler (to me) than any of the others:
x <- scan(file = textConnection("Cat 14 Dog 15 Horse 16"),
what = list(Animal=character(), Number=numeric()))
# Convert x (at this point a list) into a data.frame
as.data.frame(x)
# Animal Number
# 1 Cat 14
# 2 Dog 15
# 3 Horse 16