# Importing scientific data with uncertainties and units

I want to import scientific data from a CSV file. The data are length measurements in centimeters with uncertainties. I want to import the data with uncertainties and units into a vector - please see the code below. I can do this without units, but I am stuck how to do this with units for the whole data set. Any help is appreciated! Thanks!

Remove["Global*"];


x=VectorAround[data[[All,1]],data[[All,2]]]


I want to add units (cm) to variable x. I want it to be VectorAround[{49.9 cm, 60.2 cm, 70.1 cm, 79.8 cm , 90. cm, 100.2 cm }, {0.1 cm, 0.1 cm, 0.1 cm, 0.1 cm, 0.2 cm, 0.2 cm}].

For example, I can do this manually for two data points:

x=VectorAround[{Quantity[data[[All,1]][[1]],"Centimeters"],Quantity[data[[All,1]][[2]],"Centimeters"]},{Quantity[data[[All,2]][[1]],"Centimeters"],Quantity[data[[All,2]][[2]],"Centimeters"]}]


Is there a better way to do this? This would be highly impractical to do manually with a large data set.

• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, Feb 15 at 5:44
• 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Feb 15 at 5:44
• Try applying the function Quantity[] to the entire list of data. I think it has listable attributes meaning it should operate on all members of your data list Feb 15 at 5:45
• Welcome to the Mathematica Stack Exchange. Please load data with a few more entries, so forum participants can experiment with it. Or you can include a 1-click link to a downloadable csv file. Use an online service such as Dropbox or Google drive and make sure the link is public. Thanks.
– Syed
Feb 15 at 8:00
• @user90441 sure, but you are duplicating code. You don't need to do Quantity twice. Feb 15 at 16:26

data = Table[
{k + RandomReal[{-1,1}*k/500], Round[k/500, 0.1]}
, {k, 50, 100, 10}
]

VectorAround @@ Quantity[
Transpose@data
, "Centimeters"
]

(* VectorAround[
{
Quantity[49.9561, "Centimeters"],
Quantity[59.9273, "Centimeters"], Quantity[69.8579, "Centimeters"],
Quantity[79.977, "Centimeters"], Quantity[89.8892, "Centimeters"],
Quantity[99.9217, "Centimeters"]
},
{
Quantity[0.1, "Centimeters"],
Quantity[0.1, "Centimeters"], Quantity[0.1, "Centimeters"],
Quantity[0.2, "Centimeters"], Quantity[0.2, "Centimeters"],
Quantity[0.2, "Centimeters"]
}
]*)


Or, if you don't want a vector,

Quantity[
Around @@@ data
, "Centimeters"
]

(* {Quantity[(
Around[49.956130623394806, 0.1]), "Centimeters"], Quantity[(
Around[59.92730212004165, 0.1]), "Centimeters"], Quantity[(
Around[69.85785754443056, 0.1]), "Centimeters"], Quantity[(
Around[79.97703513294425, 0.2]), "Centimeters"], Quantity[(
Around[89.88924493447557, 0.2]), "Centimeters"], Quantity[(
Around[99.9217340877855, 0.2]), "Centimeters"]} *)


Actually this works:

VectorAround[
Quantity[data[[All, 1]], "Centimeters"],
Quantity[data[[All, 2]], "Centimeters"]]


Thanks for the help everyone!!!