Question

Good Morning All! Please forgive me I am a long time MATLAB user, first time Octave user. I have a CSV file with some sample data, the trouble is I am struggling to load the csv. The first 3 columns are categorical data i.e. column 1 has values of either men or women, column 2 gives an age group, i.e. 15-20, 30-40 and the 4th gives the frequency. I've tried CSVread, dataframe and I've tried loading it in using the IO package.

I'm a windows user. I have Octave 3.6.4 installed and an older version of IO installed 1.2.5.

Does anyone know a quick way to load this csv so that octave recognises that the first 3 columns are strings and the last is numeric

Thanks so much

James

My apologies, I am unaware how to upload the csv but I can give you a sample here:

women   18-23   no/little   26
women   18-23   important   12
women   18-23   very important  7
women   24-40   no/little   9
women   24-40   important   21
women   24-40   very important  15
women   > 40    no/little   5
women   > 40    important   14
women   > 40    very important  41
 men    18-23   no/little   40
 men    18-23   important   17
 men    18-23   very important  8
 men    24-40   no/little   17
 men    24-40   important   15
 men    24-40   very important  12
 men    > 40    no/little   8
 men    > 40    important   15
 men    > 40    very important  18
Was it helpful?

Solution

A low-level solution with textread assuming the CSV delimiter is a TAB:

[gender,age,rank,freq] = textread("foo.csv", "%s%s%s%d", "delimiter", "\t")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top