Format consist of lines, every line has set of key="value" elements.
Format example:
X="1" Y="2" Z="who are you?"
Y="4" Z="bla bla..."
X="42"
I would like to import this data into R, table or data.frame, whe开发者_运维知识库re key defines column.
The following code parses the file you provided in a 'melted' form:
data<-NULL
stream<-file("path");open(stream) #or stream<- textConnection(' X="1" Y="2" Z="who are you?" Y="4" Z="bla bla..." X="42"')
while(length(ele<-c(scan(stream,what="string",n=1,sep="="),scan(stream,what="string",n=1,sep=" ")))>0){
data<-rbind(data,ele);
}
close(stream);
print(data);
Now crystallizing:
sapply(unique(data[,1]),function(key) data[data[,1]==key,2])
精彩评论