Let's say I have some data:
data={{a1,b1},{a2,b2},{a3,b3},{a4,b4},...}
and I would like to apply the function:
f1[x_]=x*5 to every a_i element.
How can I do this?
The best solution I've found so far is to do:
MapAt[f1, data, {{1, 1}, {2, 1}, {3, 1}, {4, 1}...}]
Up to the length of my data, but I'm sure there's a more efficient solution for this.
MapAt[f1, data, {All, 1}]? – J. M.'s missing motivation May 24 '16 at 16:42Map[Apply[{f[#1], ##2} &], data], if you insist... but J.M.'s approach is best. – Emilio Pisanty May 24 '16 at 16:44Transpose@{f1[#1], #2} & @@ Transpose@dataIf yourf1isListable(and yours is ) that can give you significant speed increase. – BlacKow May 24 '16 at 16:50{f1@#, #2} & @@@ data– kglr May 24 '16 at 23:44{f1@#1, #2} & @@@ data– BlacKow May 25 '16 at 02:43#1and#are equivalent. – LLlAMnYP May 25 '16 at 07:16data.{{5, 0}, {0, 1}}– user1066 May 25 '16 at 09:54#1when you got more than one argument – BlacKow May 25 '16 at 13:45