[R] Importing name/value formatted data

Karl Ove Hufthammer karl at huftis.org
Tue Mar 6 17:06:45 CET 2012


Hi!

Does anybody know about an R function for importing paired 
name/value data, where each pair is separated by a fixed 
string (e.g., a semi-colon), and within each pair a 
different delimeter is used (e.g., an equals sign).
Example:

x="FirstName=John;LastName=Doe;Age=75;\nFirstName=Jane;LastName=Doe\nLastName=Bloggs;Age=42;FirstName=Joe"

Note that the order of the fields differ between the 
rows/records, and not all rows contain all fields.

The result should be a data frame:
  
FirstName    LastName   Age
John         Doe        75
Jane         Doe
Joe          Bloggs     42

I guess it’s not too difficult to write a function for this, 
using a bunch of strsplit functions and perhaps some 
rbind.fill and type.convert, but if there already exists such 
a function, there’s no need reinventing the wheel. :)

So, does anybody know of such a function? I tried searching 
for one, but I don’t know what this type of data format 
is called.

-- 
Karl Ove Hufthammer



More information about the R-help mailing list