Awesome! Thank you Ganesh and Marshall. Believe it or not this simple
example (and a few variants that I'm sure I can come up with now that
I've seen some of the basics) will allow me to use J much more every
day.

-Dan

On Mon, Oct 7, 2013 at 1:42 PM, Ganesh Rapolu <[email protected]> wrote:
> Because the data is boxed, all comparisons must be boxed.
>
> header =. {. data
> data =. }. data
> index =. header i. <'nameFirst'
> (<'Joe') +/@:= index {"1 data     NB. 398
>
>
> On Mon, Oct 7, 2013 at 10:25 AM, Marshall Lochbaum 
> <[email protected]>wrote:
>
>> You've got the arguments to i. backwards--the list to be searched is the
>> left argument and the element to find is on the right. Assuming that hdr
>> contains boxes, you also want the element to search for to be boxed.
>> Then you would have
>>
>> hdr i. <'NameGiven'
>>
>> to find the name column.
>>
>> Another note is that for selecting column n from a table, (n {"1 t),
>> which selects the nth element from each row of the table, is more
>> idiomatic and generally easier to use than your ((<a:; n) { t).
>>
>> Marshall
>>
>> On Mon, Oct 07, 2013 at 12:59:13PM -0700, Dan Farmer wrote:
>> > Hello all,
>> >
>> > As I have been trying to improve my J skills I've been trying to
>> > incorporate it into my daily work, but I keep hitting a wall with my
>> > ability to dig in to "tables" (i.e., read in a CSV and then explore
>> > the data).
>> >
>> > I've seen Dan Bron mention perhaps putting together a wiki page about
>> > this, but I thought maybe I could start the ball rolling here and
>> > maybe we could put something together... together. I'm using the
>> > baseball archive database as sample data since anyone can get at it
>> > (2012 CSV data, it's an 8MB zip and I'm looking at Master.csv):
>> > http://www.seanlahman.com/baseball-archive/statistics/
>> >
>> > I run off the rails pretty quickly. If I could get this type of stuff
>> > done then I could double my usage of J day to day which would be a big
>> > help in learning more. Here's my poor attempt:
>> >
>> > load 'tables/csv'
>> >
>> > t=. readcsv '/home/dan/Downloads/Master.csv'
>> >
>> >
>> > NB. Let's see how many players are named Joe?
>> >
>> > NB. Hmm... first I need to know what the headers are
>> >
>> >
>> > hdr=.0{t
>> >
>> >
>> > NB. Ok. I want rows where nameGiven
>> >
>> > NB. is Joe (I won't worry about nicknames for
>> >
>> > NB. example purposes).
>> >
>> > NB. I can get a column like this:
>> >
>> > (<a:; 1) { t
>> >
>> >
>> > NB. So if I can figure out the index of
>> >
>> > NB. nameGiven in hdr then I can select that
>> >
>> > NB. column, then do the same thing to get the "Joe's"
>> >
>> >
>> > NB. Index of?
>> >
>> > 'nameGiven' i. hdr
>> >
>> >
>> > NB. Nope, doesn't work. Looks like it treats
>> >
>> > NB. each letter as an item (I guess this is because
>> >
>> > NB. the shape of hdr is not e.g., rows x columns anymore)
>> >
>> >
>> > NB. I could of course try the inverted table thing:
>> >
>> > ifa =: <@(>"1)@|:
>> >
>> > it=. ifa t
>> >
>> >
>> > NB. Well, now my header row is split among the columns,
>> >
>> > NB. Ok let's just count with our fingers and try:
>> >
>> > 'Joe' i. 16 { it NB. 3
>> >
>> >
>> > NB. ok. I'm confused enough to stop now.
>> >
>> >
>> > Anyway, any help would be appreciated.
>> > ----------------------------------------------------------------------
>> > For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to