Trouble keeping variable names when I load data from CSV or Excel file

Thank you for your help. But loading excel file is still not easy. GAUSS is much more difficult than other programs.

Anyway, I converted breaks.xlsx to breaks.csv and loaded it as you taught. The file is 32 by 367 and the first row contains the variable names. It was loaded but all the data is shown  +DEN.

So I deleted the first row and reloaded. It works. However, how can I add the variable names?

Instead, can I the file correctly without deleting the variable name row????

 

1 Answer



0



The variable name row is still there. It is just loaded into the matrix as character data. This may help explain character data.

If you leave the data in the Excel file, you can read the first row of variable names in as a string array like this:

//calculate the cell range for the first 367 rows
//of an Excel file
range = xlsMakeRange(1|1, 1|367);
varnames = spreadSheetReadSA("myfile.xls", range, 1);

Once you convert the Excel file to CSV and read in with the load command, you can use the function cvtos to convert a character vector to a string:

//load data
load myvar[32, 367] = myfile.csv;

//create a 367x1 string array containing all variable names
varnames = cvtos(myvar[1, .]);

As an example of starting from scratch and loading in the data and variable names from your original Excel file, we can accomplish this in thre lines of code:

range = xlsMakeRange(1|1, 1|367);
varnames = spreadSheetReadSA("myfile.xls", range, 1);
mydata = spreadSheetReadM("myfile.xls", "B1", 1);

aptech

1,773

Your Answer

1 Answer

0

The variable name row is still there. It is just loaded into the matrix as character data. This may help explain character data.

If you leave the data in the Excel file, you can read the first row of variable names in as a string array like this:

//calculate the cell range for the first 367 rows
//of an Excel file
range = xlsMakeRange(1|1, 1|367);
varnames = spreadSheetReadSA("myfile.xls", range, 1);

Once you convert the Excel file to CSV and read in with the load command, you can use the function cvtos to convert a character vector to a string:

//load data
load myvar[32, 367] = myfile.csv;

//create a 367x1 string array containing all variable names
varnames = cvtos(myvar[1, .]);

As an example of starting from scratch and loading in the data and variable names from your original Excel file, we can accomplish this in thre lines of code:

range = xlsMakeRange(1|1, 1|367);
varnames = spreadSheetReadSA("myfile.xls", range, 1);
mydata = spreadSheetReadM("myfile.xls", "B1", 1);

You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.