Skip to main content
added 166 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

I am sure there is a better way, but the following does the job:

comps = exampleData[Union, "CompanyName"];
dummies = "dummy" <> ToUpperCase[#] & /@ comps;
funcs = Function[{x, y}, x -> (If[# == y, 1, 0] &)] @@@ Thread[Normal /@ {dummies, comps}];
ds2 = exampleData[All, Key["CompanyName"] /*Association[funcs]];
Dataset[Join @@@ Thread[Normal /@ {exampleData, ds2}]]

Mathematica graphics

Alternatively you can use Boole instead of If to define funcs:

 funcs= Function[{x, y}, x -> (Boole[# == y] &)] @@@ Thread[Normal /@ {dummies, comps}];

I am sure there is a better way, but the following does the job:

comps = exampleData[Union, "CompanyName"];
dummies = "dummy" <> ToUpperCase[#] & /@ comps;
funcs = Function[{x, y}, x -> (If[# == y, 1, 0] &)] @@@ Thread[Normal /@ {dummies, comps}];
ds2 = exampleData[All, Key["CompanyName"] /*Association[funcs]];
Dataset[Join @@@ Thread[Normal /@ {exampleData, ds2}]]

Mathematica graphics

I am sure there is a better way, but the following does the job:

comps = exampleData[Union, "CompanyName"];
dummies = "dummy" <> ToUpperCase[#] & /@ comps;
funcs = Function[{x, y}, x -> (If[# == y, 1, 0] &)] @@@ Thread[Normal /@ {dummies, comps}];
ds2 = exampleData[All, Key["CompanyName"] /*Association[funcs]];
Dataset[Join @@@ Thread[Normal /@ {exampleData, ds2}]]

Mathematica graphics

Alternatively you can use Boole instead of If to define funcs:

 funcs= Function[{x, y}, x -> (Boole[# == y] &)] @@@ Thread[Normal /@ {dummies, comps}];
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

I am sure there is a better way, but the following does the job:

comps = exampleData[Union, "CompanyName"];
dummies = "dummy" <> ToUpperCase[#] & /@ comps;
funcs = Function[{x, y}, x -> (If[# == y, 1, 0] &)] @@@ Thread[Normal /@ {dummies, comps}];
ds2 = exampleData[All, Key["CompanyName"] /*Association[funcs]];
Dataset[Join @@@ Thread[Normal /@ {exampleData, ds2}]]

Mathematica graphics