I have created an array with the results of a Pearson correlation between image bands. I want to convert that array into a properly structured Table. Currently, I am able to export it, but the output table looks like this:
All the lists in the array appear in the same cell. Instead, I would like to have each list in a row, and each element in the list in a column. Even better if I could add the name of the columns (band1, band2, R, p-value)
and one extract of it:
//check the correlation between bands in a stack
//var list_of_results = ee.List([]);
var myArray = []; // recommended way
//Get the names of the input bands
var bands = ["b1","b2","b3","b4"];
for (var i=0; i<bands.length;i++) {
for (var j=i+1; j<bands.length;j++) {
var sample = image.sample({'region':aoi,
'scale': 1000,
'projection': 'EPSG:4326',
'numPixels':100});
var correl = ee.Reducer.pearsonsCorrelation();
var reduced = sample.reduceColumns(correl, [bands[i], bands[j]]);
var results = [bands[i],bands[j], reduced.get('correlation'), reduced.get('p-value')];
//print(results);
myArray.push(results);
//var list_of_results = list_of_results.add(results);
}
}
//print outputs in lines
var csv = myArray.map(function(row){
//var list = [row[0], row[1], row[2], row[3]];
print(ee.String(row[0]).cat(',').cat(row[1]).cat(',').cat(row[2]).cat(',').cat(row[3]));
});
Export.table.toDrive(
ee.FeatureCollection([
ee.Feature(null, {myArray: myArray})
]));