Subset based on variable column name

Both subset and with are designed for interactive use and warnings against their use within other functions will be found in their help pages. This stems from their strategy of evaluation arguments as expressions within an environment constructed from the names of their data arguments. These column/element names would otherwise not be “objects” in the … Read more

Using grep to help subset a data frame

It’s pretty straightforward using [ to extract: grep will give you the position in which it matched your search pattern (unless you use value = TRUE). grep(“^G45”, My.Data$x) # [1] 2 Since you’re searching within the values of a single column, that actually corresponds to the row index. So, use that with [ (where you … Read more

Subsets in Prolog

Here goes an implementation: subset([], []). subset([E|Tail], [E|NTail]):- subset(Tail, NTail). subset([_|Tail], NTail):- subset(Tail, NTail). It will generate all the subsets, though not in the order shown on your example. As per commenter request here goes an explanation: The first clause is the base case. It states that the empty list is a subset of the … Read more