# How to multiply specific columns in a matrix of data?

So I need to make a plot of some ~2000 data points I have from a spreadsheet. I'm able to import the data just fine, it stores it like so

sundat

{{280.,0.082},{280.5,0.099},......{3995.,0.0087},{4000.,0.00868}}

And I can call individual data sets or points like so

sundat[[1]]

{280.,0.082}

sundat[[1,1]]

280.

There are 2002 sets of two points of data. Now I can plot it fine using ListPlot, but the raw data I have is in messy units that I want to convert to mks units. I have the conversion factor for each column, but I have no idea how to do this. I presume I need to make a new list to apply this to, but trying something like

data2 = {{sundat[[All,1]]*(conversion1)},{sundat[[All,2]]*(conversion2)}}

just totally messes up the table.

Any help would be appreciated.

• A variety of list manipulation methods can be found here Commented Sep 17, 2014 at 16:04

sundat = {{280., 0.082}, {280.5, 0.099}, {3995., 0.0087}, {4000., 0.00868}};
conversionfactors = {2., .5};

data2 = Transpose[conversionfactors Transpose[sundat]]

or

data2 = conversionfactors # & /@ sundat

both give

(* {{560.,0.041},{561.,0.0495},{7990.,0.00435},{8000.,0.00434}} *)
• Both of these work perfectly. Thank you!! Commented Sep 17, 2014 at 16:09
• @Amara, my pleasure. Thank you for the accept. And welcome to MMA.SE.
– kglr
Commented Sep 17, 2014 at 16:24

You can also use Dot:

sundat.{{2., 0}, {0, .5}}

(*  {{560., 0.041}, {561., 0.0495}, {7990., 0.00435}, {8000., 0.00434}}  *)
• For some reason I always forget this form, though I have been shown it and even used it myself (e.g. (38180)). I don't like the theoretically wasted operations, but it's so well optimized it is still often faster than alternatives. Commented Sep 17, 2014 at 20:17

Since Version 13.1 there is Threaded:

sundat = {{280., 0.082}, {280.5, 0.099}, {3995., 0.0087}, {4000., 0.00868}};

{{560., 0.041}, {561., 0.0495}, {7990., 0.00435}, {8000., 0.00434}}

Although I prefer kguler's double Transpose you could also use Inner:

sundat = {{280., 0.082}, {280.5, 0.099}, {3995., 0.0087}, {4000., 0.00868}};

Inner[Times, sundat, {2., .5}, List]
{{560., 0.041}, {561., 0.0495}, {7990., 0.00435}, {8000., 0.00434}}

Or leveraging Simon's solution from: How can I make threading more flexible?