# Operation on the first element of list only

If I have the following list:

list={{0.01, 0.037348}, {0.03, 0.165434}, {0.1, 0.263921}, {0.3,
0.560191}, {1., 0.968857}, {3., 1.50965}, {10., 2.36502}, {30.,
3.07659}, {100., 3.73412}, {300., 4.4931}, {1000., 5.06818}, {3000.,
5.65423}, {10000., 6.00944}}


How can I get the natural logarithm (Log[]) of the first element of the list (e.g. 0.01, 0.03.....10000) only while leaving the second one intact? . I would like this to apply to other lists as well of different lenghts.

• {Log[First[#]],Last[#]}&/@list will make a new list with log of the first element. – flinty Jun 28 '20 at 1:26
• This works great! @flinty. Thank you very much !!! – John Jun 28 '20 at 1:29
• Or {Log@#1, #2} & @@@ list. There are many similar questions and this will be signed as a duplicate. – Artes Jun 28 '20 at 1:50
• list[[All,1]]=Log@list[[All,1]] – OkkesDulgerci Jun 28 '20 at 2:33
• If you're ultimately planning to plot this data, you may want to look at the documentation for ListLogPlot, ListLogLinearPlot, and/or ListLogLogPlot. – Michael Seifert Jun 28 '20 at 14:04

This should be fast for large lists:

Transpose[{Log @ #, #2} & @@ Transpose[#]] & @ list

{{-4.60517, 0.037348}, {-3.50656, 0.165434}, {-2.30259, 0.263921}, {-1.20397, 0.560191},
{0., 0.968857}, {1.09861, 1.50965}, {2.30259, 2.36502}, {3.4012, 3.07659}, {4.60517,  3.73412},
{5.70378, 4.4931}, {6.90776, 5.06818}, {8.00637, 5.65423}, {9.21034, 6.00944}}


You may use MapAt.

MapAt[Log, {All, 1}]@list

{{-4.60517, 0.037348}, {-3.50656, 0.165434},
{-2.30259, 0.263921}, {-1.20397, 0.560191},
{0., 0.968857}, {1.09861, 1.50965},
{2.30259, 2.36502}, {3.4012, 3.07659},
{4.60517, 3.73412}, {5.70378, 4.4931},
{6.90776, 5.06818}, {8.00637, 5.65423},
{9.21034, 6.00944}}


Hope this helps.

In addition, in v 12.0 and greater, you may use SubsetMap

SubsetMap[Log, list, {All,1}]


{{-4.60517, 0.037348}, {-3.50656, 0.165434}, {-2.30259, 0.263921}, {-1.20397, 0.560191}, {0., 0.968857}, {1.09861, 1.50965}, {2.30259, 2.36502}, {3.4012, 3.07659}, {4.60517, 3.73412}, {5.70378, 4.4931}, {6.90776, 5.06818}, {8.00637, 5.65423}, {9.21034, 6.00944}}

newlist=Table[{Log[list[[k]]],list[[k]]},{k,1,Length[list]}]


is inelegant but will work.