Skip to content
Prev 315579 / 398503 Next

reading multiple key=value pairs per line

Hi

One option are regular expressions but you can also read data with "=" as separator.

test<-read.table("input_kvpairs.csv", sep=c("="), header=F, stringsAsFactors=F)

#use this function to split and extract numeric parts
extract<-function(x) as.numeric(sapply(strsplit(x,","),"[",1))

# and apply the function to appropriate columns
test1 <- data.frame(sapply(test[,2:3], extract), test[,4])

Now you can put names to resulting data frame see
?names

Regards
Petr