How to divide a column in table to other variables?
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Behrooz Daneshian
il 12 Gen 2023
Modificato: Stephen23
il 13 Gen 2023
Hi all
I have a table called "TEMP" reporting daily minimum temprature(TMIN), daily maximum temprature(TMAX), and daily average temprature(TAVG) for a specific location in 2004. I want to devide the 'datatype' column into 3 columns of TMIN, TMAX, and TAVG. I will do it using the following code, but I would see 'NaN' values in the new table. Can anyone help me with this regard?
load ("TEMP1.mat");
unstackedTemp = unstack(TEMP,"value","datatype");
Risposta accettata
Stephen23
il 13 Gen 2023
Modificato: Stephen23
il 13 Gen 2023
You need to specify the "GROUPINGVARIABLE" option, otherwise "...unstack treats the remaining variables as grouping variables. Each unique combination of values in the grouping variables identifies a group of rows in S that is unstacked into a single row of U." So while you might think that every three lines of TAVG, TMAX, and TMIN form a "set" of values, take a look at the column/variable "attributes": are they the same for each set? (hint: no)
Solution: specify the grouping variable to specify which data get merged onto one line.
S = load('TEMP1.mat')
T = S.TEMP
T = unstack(T,"value","datatype", "GroupingVariable","date")
As an aside, note that the "date" column/variable should probably be DATETIME, not text. This can be fixed using CONVERTVARS (even better: fix this when importing the data):
T = convertvars(T,'date','datetime')
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Tables in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!