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
One way:
# read the line
r <- read.csv("exa.Rda",sep=" ", head=F)
# every odd number index is an animal
animals <- r[,(1:ncol(r)-1)%%2==0]
# every even number index is a number
numbers <- r[,(1:ncol(r))%%2==0]
# flipping the animal row into a column
animals <- t(animals)
# flipping the number row into a column
numbers <- t(numbers)
# putting the data together
mydata <- data.frame(animals, numbers)