hi! I apologize in advance if this is a newbie dumm question, but I really can't figure it ou. I have lists of sumeric and character data on some URLs, which look like this: <photo id="5876248819" owner="13716719 at N04" secret="faf9bb7f52" server="5264" farm="6" title="our rose garden" ispublic="1" isfriend="0" isfamily="0" tags="flowers plants green rose yellow garden nikon" /> <photo id="5876248123" owner="15023277 at N02" secret="e7b8037738" server="5192" farm="6" title="Blue, red, yellow, green" ispublic="1" isfriend="0" isfamily="0" tags="blue red green grass yellow truck amusement fair fete royalmail van ldv 2011 birstall" /> <photo id="5876786530" owner="58185891 at N00" secret="54ec727b3d" server="5065" farm="6" title="Boathko" ispublic="1" isfriend="0" isfamily="0" tags="blue abstract black yellow boat seaside paint decay peelingpaint stives paintedwood stripesstripy" /> ... I have to work with some fields of each record, so I'd need to see this data as a table, but I managed to import it into R only in html format, and not with read.table or something like that, because there are many symbols that R doesn't seem to like. Any suggestion for importing this data in another way, or forcing the fields (Photo id, owner, secret...) in a table with something like a character pattern matching? Thank you in advance!! Mari -- View this message in context: http://r.789695.n4.nabble.com/import-text-records-and-set-the-fields-in-a-table-tp3627561p3627561.html Sent from the R help mailing list archive at Nabble.com.
Steven Kennedy
2011-Jun-27 22:00 UTC
[R] import text-records and set the fields in a table
As long as all the fields in each entry are the same, then the following will work df<-data.frame(photo_id=NA,owner=NA,secret=NA,server=NA,farm=NA,title=NA, ispublic=NA,isfriend=NA,isfamily=NA,tags=NA) x<-'<photo id="5876248819" owner="13716719 at N04" secret="faf9bb7f52" server="5264" farm="6" title="our rose garden" ispublic="1" isfriend="0" isfamily="0" tags="flowers plants green rose yellow garden nikon" />' y<-strsplit(x,split="=\"") tmp<-c() for (i in 2:length(y[[1]])){ tmp[i-1]<-strsplit(y[[1]][i],split="\"")[[1]][1] } df[1,]<-tmp> dfphoto_id owner secret server farm title ispublic 1 5876248819 13716719 at N04 faf9bb7f52 5264 6 our rose garden 1 isfriend isfamily tags 1 0 0 flowers plants green rose yellow garden nikon You could exend this to loop through all your data. On Mon, Jun 27, 2011 at 10:09 PM, mari681 <marianna.bolognesi at gmail.com> wrote:> hi! > I apologize in advance if this is a newbie dumm question, but I really can't > figure it ou. > > I have lists of sumeric and character data on some URLs, which look like > this: > > <photo id="5876248819" owner="13716719 at N04" secret="faf9bb7f52" > server="5264" farm="6" title="our rose garden" ispublic="1" isfriend="0" > isfamily="0" tags="flowers plants green rose yellow garden nikon" /> > > <photo id="5876248123" owner="15023277 at N02" secret="e7b8037738" > server="5192" farm="6" title="Blue, red, yellow, green" ispublic="1" > isfriend="0" isfamily="0" tags="blue red green grass yellow truck amusement > fair fete royalmail van ldv 2011 birstall" /> > > <photo id="5876786530" owner="58185891 at N00" secret="54ec727b3d" > server="5065" farm="6" title="Boathko" ispublic="1" isfriend="0" > isfamily="0" tags="blue abstract black yellow boat seaside paint decay > peelingpaint stives paintedwood stripesstripy" /> > > ... > > I have to work with some fields of each record, so I'd need to see this data > as a table, but I managed to import it into R only in html format, and not > with read.table or something like that, because there are many symbols that > R doesn't seem to like. > > Any suggestion for importing this data in another way, or forcing the fields > (Photo id, owner, secret...) in a table with something like a character > pattern matching? > > Thank you in advance!! > Mari > > -- > View this message in context: http://r.789695.n4.nabble.com/import-text-records-and-set-the-fields-in-a-table-tp3627561p3627561.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >