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, where key defines column.
Thanks!
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, where key defines column.
Thanks!
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])
Thanks for reply, i couldn't write code in comment so i placed it as answer. That variable w in second scan should be stream i guess? and why did you put n=1 ? In that case i only get first value repeatedly entered. Than i replaced dd with data, but its not ok, it seems that i read file more than once, maybe this length condition is bad? In next comment is version i tried, what do you thinj? Sorry if i did something stupid, im new in R, and this is first time i did more than call built-in funtion :)
data<-NULL
stream <- file("path")
while(length(ele<-c(scan(stream,what="string",n=-1,sep="=",quiet=TRUE,flush=FALSE),
scan(stream,what="string",n=-1,sep=" ",quiet=TRUE,flush=FALSE)))>0){
data<-rbind(data,ele);
}