Iteration over Data table

Imagine a DT:

Variable1 <- c("Name1", "Name2", "Name3", "Name4", "NA", "NA", "Name5", "Name6")
Variable2 <- c("C", "C", "N", "C", "C", "C", "N", "C")
Variable3 <- c("NA", "NA", "NA", "YES", "NO", "NotApplicable", "NA", "NA")
DT <- data.table(Variable1, Variable2, Variable3)
Variable1 Variable2 Variable3
1: Name1 C NA
2: Name2 C NA
3: Name3 N NA
4: Name4 C YES
5: NA C NO
6: NA C NotApplicable
7: Name5 N NA
8: Name6 C NA

I need to obtain a DT containing: Name4 C YES, NO, NotApplicable (in one row) is it possible by iteration over Variable1?

your request seems arbitrary because you dont propose any criteria or methodology for the relationship between the input and desired output. Taken at face value, the most direct way to achieve your desired output, is to be independent of the input and simply construct a DT with the entries you say your require.

Hi, thanks for reply. You are right. I forgot to add that I got data.table directly from csv file, so I have no influence on input data.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.