Skip to main content
deleted 1 character in body
Source Link
Jason B.
  • 72.3k
  • 3
  • 152
  • 317

Import the data as a table, convert to a Association to enable fast lookups (if you have 4GB of data then I don't recommend using a Dataset

list = ImportString["A B C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1", "Table"]; dset = Map[AssociationThread[First@list ->, #] &, Rest@list] (* {<|"A" -> 0, "B" -> 0, "C" -> 0|>, <|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 0|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>, <|"A" -> 1, "B" -> 0, "C" -> 0|>, <|"A" -> 1, "B" -> 0, "C" -> 1|>, <|"A" -> 1, "B" -> 1, "C" -> 0|>, <|"A" -> 1, "B" -> 1, "C" -> 1|>} *) 

Use Select to get the rows you want,

Select[dset, #A == 0 && #C == 1 &] (* {<|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>} *) 

From here, it's not too painful to get the indices from the rows,

Select[dset, #A == 0 && #C == 1 &] // (Position[dset, Alternatives @@ #] &) // Flatten (* {2, 4} *) 

Import the data as a table, convert to a Association to enable fast lookups (if you have 4GB of data then I don't recommend using a Dataset

list = ImportString["A B C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1", "Table"]; dset = Map[AssociationThread[First@list -> #] &, Rest@list] (* {<|"A" -> 0, "B" -> 0, "C" -> 0|>, <|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 0|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>, <|"A" -> 1, "B" -> 0, "C" -> 0|>, <|"A" -> 1, "B" -> 0, "C" -> 1|>, <|"A" -> 1, "B" -> 1, "C" -> 0|>, <|"A" -> 1, "B" -> 1, "C" -> 1|>} *) 

Use Select to get the rows you want,

Select[dset, #A == 0 && #C == 1 &] (* {<|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>} *) 

From here, it's not too painful to get the indices from the rows,

Select[dset, #A == 0 && #C == 1 &] // (Position[dset, Alternatives @@ #] &) // Flatten (* {2, 4} *) 

Import the data as a table, convert to a Association to enable fast lookups (if you have 4GB of data then I don't recommend using a Dataset

list = ImportString["A B C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1", "Table"]; dset = Map[AssociationThread[First@list , #] &, Rest@list] (* {<|"A" -> 0, "B" -> 0, "C" -> 0|>, <|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 0|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>, <|"A" -> 1, "B" -> 0, "C" -> 0|>, <|"A" -> 1, "B" -> 0, "C" -> 1|>, <|"A" -> 1, "B" -> 1, "C" -> 0|>, <|"A" -> 1, "B" -> 1, "C" -> 1|>} *) 

Use Select to get the rows you want,

Select[dset, #A == 0 && #C == 1 &] (* {<|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>} *) 

From here, it's not too painful to get the indices from the rows,

Select[dset, #A == 0 && #C == 1 &] // (Position[dset, Alternatives @@ #] &) // Flatten (* {2, 4} *) 
deleted 4 characters in body
Source Link
Jason B.
  • 72.3k
  • 3
  • 152
  • 317

Import the data as a table, convert to a Association to enable fast lookups (if you have 4GB of data then I don't recommend using a Dataset

list = ImportString["A B C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1", "Table"]; dset = Map[Association @@ Thread[First@listMap[AssociationThread[First@list -> #] &, Rest@list] (* {<|"A" -> 0, "B" -> 0, "C" -> 0|>, <|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 0|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>, <|"A" -> 1, "B" -> 0, "C" -> 0|>, <|"A" -> 1, "B" -> 0, "C" -> 1|>, <|"A" -> 1, "B" -> 1, "C" -> 0|>, <|"A" -> 1, "B" -> 1, "C" -> 1|>} *) 

Use Select to get the rows you want,

Select[dset, #A == 0 && #C == 1 &] (* {<|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>} *) 

From here, it's not too painful to get the indices from the rows,

Select[dset, #A == 0 && #C == 1 &] // (Position[dset, Alternatives @@ #] &) // Flatten (* {2, 4} *) 

Import the data as a table, convert to a Association to enable fast lookups (if you have 4GB of data then I don't recommend using a Dataset

list = ImportString["A B C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1", "Table"]; dset = Map[Association @@ Thread[First@list -> #] &, Rest@list] (* {<|"A" -> 0, "B" -> 0, "C" -> 0|>, <|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 0|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>, <|"A" -> 1, "B" -> 0, "C" -> 0|>, <|"A" -> 1, "B" -> 0, "C" -> 1|>, <|"A" -> 1, "B" -> 1, "C" -> 0|>, <|"A" -> 1, "B" -> 1, "C" -> 1|>} *) 

Use Select to get the rows you want,

Select[dset, #A == 0 && #C == 1 &] (* {<|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>} *) 

From here, it's not too painful to get the indices from the rows,

Select[dset, #A == 0 && #C == 1 &] // (Position[dset, Alternatives @@ #] &) // Flatten (* {2, 4} *) 

Import the data as a table, convert to a Association to enable fast lookups (if you have 4GB of data then I don't recommend using a Dataset

list = ImportString["A B C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1", "Table"]; dset = Map[AssociationThread[First@list -> #] &, Rest@list] (* {<|"A" -> 0, "B" -> 0, "C" -> 0|>, <|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 0|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>, <|"A" -> 1, "B" -> 0, "C" -> 0|>, <|"A" -> 1, "B" -> 0, "C" -> 1|>, <|"A" -> 1, "B" -> 1, "C" -> 0|>, <|"A" -> 1, "B" -> 1, "C" -> 1|>} *) 

Use Select to get the rows you want,

Select[dset, #A == 0 && #C == 1 &] (* {<|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>} *) 

From here, it's not too painful to get the indices from the rows,

Select[dset, #A == 0 && #C == 1 &] // (Position[dset, Alternatives @@ #] &) // Flatten (* {2, 4} *) 
Source Link
Jason B.
  • 72.3k
  • 3
  • 152
  • 317

Import the data as a table, convert to a Association to enable fast lookups (if you have 4GB of data then I don't recommend using a Dataset

list = ImportString["A B C 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1", "Table"]; dset = Map[Association @@ Thread[First@list -> #] &, Rest@list] (* {<|"A" -> 0, "B" -> 0, "C" -> 0|>, <|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 0|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>, <|"A" -> 1, "B" -> 0, "C" -> 0|>, <|"A" -> 1, "B" -> 0, "C" -> 1|>, <|"A" -> 1, "B" -> 1, "C" -> 0|>, <|"A" -> 1, "B" -> 1, "C" -> 1|>} *) 

Use Select to get the rows you want,

Select[dset, #A == 0 && #C == 1 &] (* {<|"A" -> 0, "B" -> 0, "C" -> 1|>, <|"A" -> 0, "B" -> 1, "C" -> 1|>} *) 

From here, it's not too painful to get the indices from the rows,

Select[dset, #A == 0 && #C == 1 &] // (Position[dset, Alternatives @@ #] &) // Flatten (* {2, 4} *)