I have a file in that has different data informations about a certain population.
Example of file format:
1880,Mary,F,7065
1880,Anna,F,2604
1880,Emma,F,2003
1880,Elizabeth,F,1939
We can interpret this data as “In the year 1880, 7065 female babies were born named Mary"
I have a function that reads from the file
fromFile(name:String):List[List[String]]
fromFile returns a list of lists:
List( List("1880","Mary", "F","7065"))
I am having trouble figuring out how to get the data and parsing it out for a function like this, which takes a nested list and a number,and returns a list of of entries of such year. For example if 'n' is 1880, then the return list would return all info about Mary.
object readFile{
val years = CSV.fromFile("my_file.csv")
def yearIs(data: List[List[String]], n: Int): List[List[String]] =
??
}
I trying to figure out how to access each element in the returned list and compare it to the given 'int', and return all the data.
yearIstakes adataparameter, but your code usesyears.. From your comment, theline.splitwill return an array of entries, so you can't just compare ton. But it's not clear that you need to split at all, sincefromFileseems to return a list of lists of strings, presumably a list of rows each with multiple strings?