# Using imported data in further calculations

I have quite a lot of data in an Excel file, which I have to use in further calculations. The transformation should map a data point with thre coordinates into a two coordinate result. Example: $(r,g,b)\mapsto(r/2 + g, r \, tan(\pi/3)/2)$.

So far I have tried the following, but it doesn't work since the result is the same as the imported data.

coords[{r_, g_, b_}] := {r/2 + g, r Tan[Pi/3]/2};
data = Import["file.xlsx"]
coords[data]


### Edit

OK, i'm sorry for not posting the data earlier:

{{{"0.1", "0.65", "0.25"}, {"0.8", "0.1", "0.1"}, {"0.7", "0.15", "0.15"},
{"0.6", "0.1", "0.3"}, {"0.5", "0.2", "0.3"}, {"0.4", "0.1", "0.5"},
{"0.3", "0.3", "0.4"}, {"0.2", "0.1", "0.7"}, {"0.1", "0.8", "0.1"}}}

-
How about coords/@data? Without data it is difficult to help you –  Yves Klett Feb 27 at 22:04

You have two issues... first, the data is in the form of strings, so needs to be changed into numbers (this is the ToExpression). The Flatten removes an extra pair of brackets, and then you can Map the coords function onto the data. The symbols /@ are shorthand for this mapping.

stringData = {{{"0.1", "0.65", "0.25"}, {"0.8", "0.1", "0.1"},
{"0.7", "0.15", "0.15"}, {"0.6", "0.1", "0.3"}, {"0.5", "0.2", "0.3"},
{"0.4", "0.1", "0.5"}, {"0.3", "0.3", "0.4"}, {"0.2", "0.1", "0.7"}, {"0.1", "0.8", "0.1"}}};
data = Flatten[ToExpression[stringData], 1];
coords[{r_, g_, b_}] := {r/2 + g, r Tan[Pi/3]/2};
coords /@ data


{{0.7, 0.0866025}, {0.5, 0.69282}, {0.5, 0.606218}, {0.4, 0.519615},

Map is very common -- it's one way to replace a Do or For looping structure. Flatten is really useful for removing extra parentheses. –  bill s Feb 27 at 22:35
@user12073 You can also use Dot: data.Transpose@{{1/2., 1., 0.}, {Tan[Pi/3]/2., 0., 0.}}, which can be much faster on large data sets. –  Michael E2 Feb 28 at 4:26