2
$\begingroup$

I have a big list of Gibbs vs T data. Temperatures have to be converted to kelvin.

List={{50.011, -40.177}, {50.997, -39.709}, {51.993, -39.881}, {52.999,-39.813}}

How can I add 273.15 to the first number of each sublist in List?

$\endgroup$
  • 4
    $\begingroup$ You can't use List as a variable name since it's a built-in symbol. If the variable name were list, the solution would be # + {273.15, 0} & /@ list. $\endgroup$ – C. E. Oct 26 '16 at 6:19
  • 3
    $\begingroup$ The solution in C.E.'s comment works well in this case. Note, however, that {#1 + 273.15, ##2} & @@@ list or even MapAt[ # + 273.15 &, 1 ] /@ list might generalize better to different situations. $\endgroup$ – jjc385 Oct 26 '16 at 6:30
  • $\begingroup$ MapAt[ QuantityMagnitude@ UnitConvert[Quantity[#, "Celsius"], "Kelvin"]&,list, {All, 1}] :) $\endgroup$ – george2079 Oct 26 '16 at 13:52
4
$\begingroup$

Here are some possible solutions

{#[[1]] + 273.15, #[[2]]} & /@ list

MapAt[# + 273.15 &, list, {All, 1}]

Transpose@{list[[All, 1]] + 273.15, list[[All, 2]]}

list + ConstantArray[{273.15, 0}, Length@list]
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.