This will do the trick:
var group1 = XDocument.DOM.selectSingleNode("/my:myFields/my:group1");
var group2 = XDocument.DOM.createNode("element", "my:group2", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-10-26T11:56:24");
group1.appendChild(group2);
You'll of course need to replace the path, node name, and namespace URI with your own.