Re: Using HashBags
El Saturday, 07 de April del 2018 a les 16:47, Siavash va escriure: Don't know if there is a better way, but assuming you don't have control over the data, you can do this: my Bag $docents = @rows.map(*.pairup).Bag; This is what I was looking for! I did not came across the 'pairup' method. Many thanks! Cheers! On 2018-04-07 10:10:52 GMT, mimosinnet wrote: Hi all, I do not seem to be able to get this done with the Bag or BagHash type: --- dd @rows; Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]] my %docents; for @rows -> @row { %docents{ @row[0] } += @row[1]; } dd %docents; Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8), :MPu(8)} --- As I understand it, this would better be achieved with the Bag or BagHash type. What would be the easy way? Thanks! -- Joan Pujol Tarrés Departament de Psicologia Social Facultat de Psicologia, Universitat Autònoma de Barcelona Despatx: B5-036 (Passadís Departament Psicologia Social) Edifici B, 08193 Bellaterra (Barcelona), Fax: +34 935812001 http://orcid.org/-0002-0462-3278 https://portalrecerca.csuc.cat/orcid/-0002-0462-327
Re: Using HashBags
You can do the following my %b is BagHash = … or my %b := bag … On Sun, Apr 8, 2018 at 10:54 AM, Vittore Scolariwrote: > I answer myself: with % you get an Hash > > On Sun, Apr 8, 2018 at 5:53 PM, Vittore Scolari > wrote: >> >> Wouldn't here be better to use the % sigil? >> >> my %docents = bag @rows.map: -> @row {@row[0] xx @row[1]}; >> >> >> >> On Sat, Apr 7, 2018 at 1:02 PM, Fernando Santagata >> wrote: >>> >>> Hi, >>> >>> I'm not sure that I've understood what you need. >>> If you get that array of arrays from a another process @rows and you wish >>> to convert it into a Bag you can do this: >>> >>> my @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], >>> ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], ["FV", >>> 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], >>> ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]]; >>> my Bag $docents = bag @rows.map: -> @row {@row[0] xx @row[1]}; >>> dd $docents; >>> >>> # Bag $docents = ("JP"=>8,"FV"=>8,"FE"=>4,"MPu"=>8,"MM"=>8,"JF"=>9).Bag >>> >>> Otherwise you can start collecting those pairs into a Bag from the start, >>> but we would need more details then. >>> >>> HTH >>> >>> >>> On Sat, Apr 7, 2018 at 12:10 PM, mimosinnet wrote: Hi all, I do not seem to be able to get this done with the Bag or BagHash type: --- dd @rows; > Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], > ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", > 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], > ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]] my %docents; for @rows -> @row { %docents{ @row[0] } += @row[1]; } dd %docents; > Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8), > :MPu(8)} --- As I understand it, this would better be achieved with the Bag or BagHash type. What would be the easy way? Thanks! -- (≧∇≦) Mimosinnet (Linux User: #463211) >>> >>> >>> >>> >>> -- >>> Fernando Santagata >> >> >
Re: Using HashBags
I answer myself: with % you get an Hash On Sun, Apr 8, 2018 at 5:53 PM, Vittore Scolariwrote: > Wouldn't here be better to use the % sigil? > > my %docents = bag @rows.map: -> @row {@row[0] xx @row[1]}; > > > > On Sat, Apr 7, 2018 at 1:02 PM, Fernando Santagata < > nando.santag...@gmail.com> wrote: > >> Hi, >> >> I'm not sure that I've understood what you need. >> If you get that array of arrays from a another process @rows and you wish >> to convert it into a Bag you can do this: >> >> my @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], >> ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], ["FV", >> 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], >> ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]]; >> my Bag $docents = bag @rows.map: -> @row {@row[0] xx @row[1]}; >> dd $docents; >> >> # Bag $docents = ("JP"=>8,"FV"=>8,"FE"=>4,"MPu"=>8,"MM"=>8,"JF"=>9).Bag >> >> Otherwise you can start collecting those pairs into a Bag from the start, >> but we would need more details then. >> >> HTH >> >> >> On Sat, Apr 7, 2018 at 12:10 PM, mimosinnet wrote: >> >>> Hi all, >>> >>> I do not seem to be able to get this done with the Bag or BagHash type: >>> >>> --- >>> dd @rows; >>> >>> Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]] >>> >>> my %docents; >>> for @rows -> @row { >>> %docents{ @row[0] } += @row[1]; >>> } >>> >>> dd %docents; >>> >>> Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8), :MPu(8)} >>> >>> --- >>> >>> As I understand it, this would better be achieved with the Bag or >>> BagHash type. What would be the easy way? >>> >>> Thanks! >>> -- >>> (≧∇≦) Mimosinnet (Linux User: #463211) >>> >> >> >> >> -- >> Fernando Santagata >> > >
Re: Using HashBags
Wouldn't here be better to use the % sigil? my %docents = bag @rows.map: -> @row {@row[0] xx @row[1]}; On Sat, Apr 7, 2018 at 1:02 PM, Fernando Santagata < nando.santag...@gmail.com> wrote: > Hi, > > I'm not sure that I've understood what you need. > If you get that array of arrays from a another process @rows and you wish > to convert it into a Bag you can do this: > > my @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", > 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], ["FV", 2], > ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", > 2], ["JP", 2], ["JP", 2], ["JF", 4]]; > my Bag $docents = bag @rows.map: -> @row {@row[0] xx @row[1]}; > dd $docents; > > # Bag $docents = ("JP"=>8,"FV"=>8,"FE"=>4,"MPu"=>8,"MM"=>8,"JF"=>9).Bag > > Otherwise you can start collecting those pairs into a Bag from the start, > but we would need more details then. > > HTH > > > On Sat, Apr 7, 2018 at 12:10 PM, mimosinnetwrote: > >> Hi all, >> >> I do not seem to be able to get this done with the Bag or BagHash type: >> >> --- >> dd @rows; >> >> Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], >>> ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", >>> 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], >>> ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]] >>> >> >> my %docents; >> for @rows -> @row { >> %docents{ @row[0] } += @row[1]; >> } >> >> dd %docents; >> >> Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8), :MPu(8)} >>> >> >> --- >> >> As I understand it, this would better be achieved with the Bag or BagHash >> type. What would be the easy way? >> >> Thanks! >> -- >> (≧∇≦) Mimosinnet (Linux User: #463211) >> > > > > -- > Fernando Santagata >
Re: Using HashBags
Hi, Don't know if there is a better way, but assuming you don't have control over the data, you can do this: my Bag $docents = @rows.map(*.pairup).Bag; On 2018-04-07 10:10:52 GMT, mimosinnet wrote: > Hi all, > > I do not seem to be able to get this done with the Bag or BagHash > type: > > --- > dd @rows; > >> Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], >> ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], >> ["FV", 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], >> ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]] > > my %docents; > for @rows -> @row { > %docents{ @row[0] } += @row[1]; > } > > dd %docents; > >> Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8), >> :MPu(8)} > > --- > > As I understand it, this would better be achieved with the Bag or > BagHash type. What would be the easy way? > > Thanks!
Re: Using HashBags
Hi, I'm not sure that I've understood what you need. If you get that array of arrays from a another process @rows and you wish to convert it into a Bag you can do this: my @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]]; my Bag $docents = bag @rows.map: -> @row {@row[0] xx @row[1]}; dd $docents; # Bag $docents = ("JP"=>8,"FV"=>8,"FE"=>4,"MPu"=>8,"MM"=>8,"JF"=>9).Bag Otherwise you can start collecting those pairs into a Bag from the start, but we would need more details then. HTH On Sat, Apr 7, 2018 at 12:10 PM, mimosinnetwrote: > Hi all, > > I do not seem to be able to get this done with the Bag or BagHash type: > > --- > dd @rows; > > Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", >> 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], >> ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", >> 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]] >> > > my %docents; > for @rows -> @row { > %docents{ @row[0] } += @row[1]; > } > > dd %docents; > > Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8), :MPu(8)} >> > > --- > > As I understand it, this would better be achieved with the Bag or BagHash > type. What would be the easy way? > > Thanks! > -- > (≧∇≦) Mimosinnet (Linux User: #463211) > -- Fernando Santagata
Using HashBags
Hi all, I do not seem to be able to get this done with the Bag or BagHash type: --- dd @rows; Output: Array @rows = [["JF", 1], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["FV", 2], ["FV", 2], ["JF", 2], ["MM", 2], ["MPu", 2], ["MM", 2], ["FE", 2], ["FV", 2], ["MPu", 2], ["JP", 2], ["JP", 2], ["JF", 4]] my %docents; for @rows -> @row { %docents{ @row[0] } += @row[1]; } dd %docents; Output: Hash %docents = {:FE(4), :FV(8), :JF(9), :JP(8), :MM(8), :MPu(8)} --- As I understand it, this would better be achieved with the Bag or BagHash type. What would be the easy way? Thanks! -- (≧∇≦) Mimosinnet (Linux User: #463211)