If I have the following list:
https://pastebin.com/nqyf4yY5
How can I find the closest value to "89" in the "T[C]" column and its corresponding value in the "DH,aged-DH,unaged (J/g)" column?.
Thank you in advanced,
Given your data
data[[5]] // InputForm
(* {"Time(s)", "T[C]", "K(T)=k^(1/n)",
"dx/dT", "x(t)",
"DH,aged-DH,unaged (J/g)",
"Check dx"} *)
values = data[[6 ;;]];
You are asking for data that corresponds to headers for columns {2, 6}.
The entry for the value of T[C]
(column 2) closest to 89
entry = values[[Position[values[[All, 2]],
Nearest[values[[All, 2]], 89][[1]]][[1, 1]]]]
(* {3.87*10^-6, 89.2592, 5.13099, 0.0107504, 0.0102723, 0.0123268, 0.0000417117} *)
The desired values are
entry[[{2, 6}]]
(* {89.2592, 0.0123268} *)
TableForm
so literally when I inpur data
I will get rows and columns as if it were an excel file, where the headers are in the 5 row the data starts in the 6 row. When I pasted the input from data
it looks like what I pasted in here where the output is not in TableForm
. Is there any way to transform my data
to into how I have it in here?.The reason I ask if because it seems that when it is as in TableForm the code does seem to work. Thank you
$\endgroup$
TableForm
is a wrapper and intended only for display, you do not want it included in a definition of data
. That is rather than data = TableForm[datavalues]
you would instead use TableForm[data = datavalues]
. That way the definition of data
does not contain the wrapper.
$\endgroup$
Commented
May 3, 2020 at 21:37
data = Import["~/Downloads/data.txt"] // ToExpression // Part[#, 6 ;;] &;
nf = Nearest[data[[All, 2]] -> {"Index", "Element"}];
data[[nf[89][[1, 1]]]]
(* {3.87*10^-6, 89.2592, 5.13099, 0.0107504, 0.0102723, 0.0123268, 0.0000417117} *)
data // ToExpression // Part[#, 6 ;;] &;
it does not work. What should I put her to make it work if I already have the data and I don't need to import it?. Thank you
$\endgroup$
List
, then you do not need the ToExpression
. Not sure if you need the Part[#, 6::]&
, depends on the list structure.
$\endgroup$
Commented
May 3, 2020 at 21:47
With your data, assuming the column headings are in row 5:
data[[5]]
(* {"Time(s)","T[C]","K(T)=k^(1/n)","dx/dT","x(t)","DH,aged-DH,unaged (J/g)","Check dx"} *)
... find the column numbers for columns "T[C]" and "DH,aged-DH,unaged (J/g)":
{c1, c2} = Flatten@{
Position[data[[5]], "T[C]"],
Position[data[[5]], "DH,aged-DH,unaged (J/g)"]};
It's easier to search the data without the extra rows at the top. When there are multiple values that match, we find only the first one. Get the nearest value and the matching column:
values = data[[6 ;;]];
v = 89.;
First@Extract[values[[All, {c1, c2}]],
Position[values[[All, c1]], First@Nearest[values[[All, c1]], v]]]
(* {89.2592, 0.0123268} *)
T[C]
?{"Delta t (s)", 1.*10^-8}, {"q (K/s)", 1000}, {""}, {""}, {"Time(s)", "T[C]", "K(T)=k^(1/n)", "dx/dT", "x(t)", "DH,aged-DH,unaged (J/g)", "Check dx"}
$\endgroup$90.01
up to89.2592
(those in the second element of the list). The "DH,aged-DH,unaged (J/g)" column would be the values that start in0.0000159219
up to0.0123268
(those in the sixth position of the lists). I hope that helps clarify it. $\endgroup$