2

I have CSV files with numeric data and I would like to perform analysis on this data. I am hoping that using APL will give me more flexibility than reading this into mysql and performing selects. But to start with I would like to do simple extractions like 'select * from mydata where col1 = 2020'. So far I understand I can use Compress. But for that I need to know the expression that would yield the boolean array for the left argument of compress (i.e. the APL version of 'where col1 = 2020'). Online searches did not get me anywhere in that department.

Adám
  • 6,573
  • 20
  • 37
Rudi Angela
  • 1,463
  • 1
  • 12
  • 20

1 Answers1

1

You are indeed right in your speculations.

"col1 = 2020" would be mydata[;1] = 2020 so the entire thing is (mydata[;1] = 2020) ⌿ mydata

My father liked to define

∇ data ← data where condition
  data ← condition⌿data
∇

so he could write things like data where data[;1] = 2020

Utilising Dyalog APL features

Dyalog APL provides some notational niceties:

  • The inline expression can be written as mydata ⌿⍨ mydata[;1] = 2020
  • The above definition of where can be written simply as where ← ⌿⍨
Adám
  • 6,573
  • 20
  • 37
  • I see. Nice! Curious: is there a way to avoid repeating the mydata reference? – Rudi Angela Nov 23 '21 at 12:49
  • @RudiAngela There are many variations possible, especially if you begin defining operators. E.g. `select ← {⍵ ⌿⍨ ⍺⍺ ⍵} ⋄ col ← ⌷⍤1⍨` allows you to write `(2020=col∘1)select mydata` or you could define `col ← {⍵ ⌿⍨ ⍺ ⍺⍺ ⍵[;⍵⍵]} ⋄ in←⊢` and write `2020 = col 1 in mydata` – Adám Nov 23 '21 at 13:00
  • @RudiAngela Feel free to visit https://apl.chat to discuss further. – Adám Nov 23 '21 at 13:01
  • Will do. Thanks for the tip. – Rudi Angela Nov 23 '21 at 14:04