One more -- matching to a list (joining tables)
NB. Get the names of everyone from the frequency table with exactly 10
matches
]namesTen=. > 0}"1 (10 ([: I. =) (> 1{"1 nameFrequency)) { nameFrequency
┌─────┬─────┬─────┬─────┬─────┬──────┬─────┬──────┬────────┬─────┐
│Ruben│Paddy│Cecil│Chico│Edwin│Martin│Kelly│Junior│Jonathan│Duane│
└─────┴─────┴─────┴─────┴─────┴──────┴─────┴──────┴────────┴─────┘
namesTenRows=.(; L:0 > (3 : '(<y) ([: I. =) names' ) each namesTen) { data
NB. Get the unique names in our subset to validate it matches the above
] ~. (colIdx <'nameFirst') {"1 namesTenRows
┌─────┬─────┬─────┬─────┬─────┬──────┬─────┬──────┬────────┬─────┐
│Ruben│Paddy│Cecil│Chico│Edwin│Martin│Kelly│Junior│Jonathan│Duane│
└─────┴─────┴─────┴─────┴─────┴──────┴─────┴──────┴────────┴─────┘
Is there a better way to find indices of a subset within a greater list?
This is my hacky solution
find=.('a';'b';'q')
list=.('a';'b';'z';'c';'a';'q')
] (; > L:0 (3 : '(<y) ([: I. =) list' ) each find) { list
┌─┬─┬─┬─┐
│a│a│b│q│
└─┴─┴─┴─┘
find xxx list
On Tue, Oct 8, 2013 at 7:14 AM, Ric Sherlock <[email protected]> wrote:
> A relatively simple adverb like the one below can be useful if you a
> repeatedly trying to access different fields in the table:
>
> NB.*getFields a Returns fields (columns) from y specified in x
>
> NB. EG: 'fieldname' tablehdr getFields table
>
> NB. EG: ('Lastname';'Firstname') hdr getFields dat
>
> NB. y is: table of records
>
> NB. m is: list of boxed field names in y
>
> NB. x is: list of boxed field names to return
>
> getFields=: 1 : 0
>
> :
>
> flds=. boxopen x
>
> idx=. m i. flds
>
> idx {"1 y
>
> )
>
>
> require 'tables/csv'
>
> 'hdr dat'=: split readcsv 'c:/tmp/master.csv'
>
>
> 4{. dat hdr getFields~ 'nameFirst';'birthYear';'weight'
>
>
> ┌──────┬────┬───┐
>
> │Hank │1934│180│
>
> ├──────┼────┼───┤
>
> │Tommie│1939│190│
>
> ├──────┼────┼───┤
>
> │Don │1954│190│
>
> ├──────┼────┼───┤
>
> │Andy │1972│184│
>
> └──────┴────┴───┘
>
>
>
>
> On Tue, Oct 8, 2013 at 11:39 PM, Joe Bogner <[email protected]> wrote:
>
> > Here are a couple other examples:
> >
> > NB. Convert years to a flat list of numbers
> >
> > birthYears=. , L:0 (> ". each ((colIdx <'birthYear') {"1 data))
> >
> >
> > NB. Find players born between 1930 and 1950 named Hank
> >
> > (I. (birthYears > 1930) * (birthYears < 1950) * (names = <'Hank')) { data
> >
> >
> > NB. Find players born between 1930 and 1950 named Hank or Tommie
> >
> > (I. (birthYears > 1930) * (birthYears < 1950) * ( (names = <'Hank') +
> > (names = <'Tommie'))) { data
> >
> >
> >
> > NB. http://www.jsoftware.com/jwiki/Essays/DataStructures
> >
> > diff=: -. [
> >
> > intersect=: e. # [
> >
> > union=: ~.@,
> >
> >
> > in=: ] ([: I. =)~ [: < [ NB. 4 : '(<x) ([: I. =)
> y'
> >
> > inT=: 4 : 'x in (colIdx <y) {"1 data'
> >
> >
> > NB. Another style
> >
> > NB. Hank or Tommie - the union of indices
> >
> > (('Hank' inT 'nameFirst') union ('Tommie' inT 'nameFirst')) { data
> >
> >
> > NB. Hank or Tommie AND born in Cuba
> >
> > ((('Hank' inT 'nameFirst') union ('Tommie' inT 'nameFirst')) intersect
> > ('Cuba' inT 'birthCountry')) { data
> >
> >
> >
> > On Tue, Oct 8, 2013 at 3:50 AM, R.E. Boss <[email protected]> wrote:
> >
> > > So 'data' was plural?
> > >
> > >
> > > R.E. Boss
> > >
> > > (Add your info to
> http://www.jsoftware.com/jwiki/Community/Demographics)
> > >
> > >
> > > > -----Original Message-----
> > > > From: [email protected] [mailto:programming-
> > > > [email protected]] On Behalf Of Henry Rich
> > > > Sent: dinsdag 8 oktober 2013 3:52
> > > > To: [email protected]
> > > > Subject: Re: [Jprogramming] Slicing and dicing tables
> > > >
> > > > That is what he meant, but it's a minority opinion.
> > > >
> > > > Henry Rich
> > > >
> > > > On 10/7/2013 8:56 PM, Dan Bron wrote:
> > > > > You mean " 'data' is plural " .
> > > > >
> > > > > -Dan
> > > > >
> > > > > PS: http://en.m.wikipedia.org/wiki/Muphry's_law
> > > > >
> > > > > (Yes, that link is spelled correctly :)
> > > > >
> > > > > Please excuse typos; composed on a handheld device.
> > > > >
> > > > > On Oct 7, 2013, at 8:00 PM, Eldon Eller <[email protected]>
> wrote:
> > > > >
> > > > >> Data are plural.
> > > > >>
> > > > >> On 10/07/2013 02:04 PM, Dan Bron wrote:
> > > > >>> Ganesh Rapolu
> > > > >>>> Because the data is boxed, all comparisons must be boxed.
> > > > >>> This was very well put (one short sentence which both clarifies
> the
> > > > >>> problem and justifies the solution).
> > > > >>>
> > > > >>> -Dan
> > > > >>>
> > > > >>>
> > > > >>>
> > > > >>>
> > --------------------------------------------------------------------
> > > > >>> -- 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
> > >
> > > ----------------------------------------------------------------------
> > > 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