I'm trying to read a csv file and return it as an array of arrays of doubles (Array[Array[Double]]
). It's pretty clear how to read in a file line by line and immediately print it out, but not how to store it in a two-dimensional array.
def readCSV() : Array[Array[Double]] = {
val bufferedSource = io.Source.fromFile("/testData.csv")
var matrix :Array[Array[Double]] = null
for (line <- bufferedSource.getLines) {
val cols = line.split(",").map(_.trim)
matrix = matrix :+ cols
}
bufferedSource.close
return matrix
}
Had some type issues and then realized I'm not doing what I thought I was doing. Any help pointing me on the right track would be very appreciated.