How to read a .dat file with column headings and intermittent NAs

I have a .dat files that were generated with R so they have column headings and the missing values are replaced with “NA”. Is there a way to read these files to a ttree? Thanks in anticipation to your help.

Hello,

try this function:
https://root.cern.ch/doc/master/classTTree.html#a9c8da1fbc68221b31c21e55bddf72ce7

Or see this section in the User’s guide:
https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#example-5-import-an-ascii-file-into-a-ttree

Thanks StephanH for the links. I have seen both documents before posting the question. The ReadFile breaks when I declare either of the columns as a double/float because of the header row and the NAs in the vector.

I was able to solve this by looping over rows of the vector (as a string) in each of the .dat files using the “getLine” command. This way I was able to test for NAs and reject them. I then ran “atof” on the string before filing them in the tree.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.