Skip to content

Commit 171af6d

Browse files
committed
feat: Add selectRows function to select rows by index
1 parent 3c069b3 commit 171af6d

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

  • dataframe-operations/src/DataFrame/Operations

dataframe-operations/src/DataFrame/Operations/Subset.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,19 @@ selectBy xs df = select finalSelection df
370370
where
371371
ixs = V.ifoldl' (\acc' i c -> if f c then i : acc' else acc') [] (columns df)
372372

373+
{- | O(k * n) select rows by index
374+
375+
> selectRows [0, 2, 4] df
376+
-}
377+
selectRows :: [Int] -> DataFrame -> DataFrame
378+
selectRows ixs df =
379+
df
380+
{ columns = V.map (atIndicesStable ixs') (columns df)
381+
, dataframeDimensions = (VU.length ixs', snd (dataframeDimensions df))
382+
}
383+
where
384+
ixs' = VU.fromList ixs
385+
373386
{- | O(n) inverse of select
374387
375388
> exclude ["Name"] df

0 commit comments

Comments
 (0)