Group Abstract Group Abstract

Message Boards Message Boards

0
|
86 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How can I use Function and Slot with variable names in slot?

Posted 5 days ago

I am trying to use a Function in AggregateRows of Tabular data.
I need to add the values of several columns of the data.

I am using this expression:

ColumnKeys[itersela][[i]] -> 
 Function[   Total[ #[   ColumnKeys[itersela][[i]]   ]  ]    ]

But this doesn't work. It works with specific names of Keys after #, but in this case, I will use variable Keys (the Key name is given by ColumnKeys[itersela][[i]] for several values of i.

How can I make this work?

5 Replies
Posted 5 days ago
POSTED BY: Eric Rimbey

Thank you Gianluca. I couldn't make it work this way. Eric's solution worked!

Thank you Eric. It works. You fully understood my problem.

This is my code and image of results:enter image description here tab = AggregateRows[ itersela, Table[ ColumnKeys[itersela][[i]] -> Function[ Evaluate[
Total[ #[ColumnKeys[itersela][[i]] ] ]
]] , {i, 10, 22} ], "ENTIDAD" ]

Posted 5 days ago

Slightly easier would be to just use Slot

POSTED BY: Eric Rimbey

Is the ColumnKeys[itersela][[i]] a string? To obtain the symbol #colKey you may try StringJoin:

ColumnKeys[itersela][[i]] -> 
 Function[Total[ToExpression[StringJoin[{"#", ColumnKeys[itersela][[i]]}]]]]
POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard