Hi,

 

I have a csv file that roughly looks like this:

 

 

Year,Name of country 1, Name of country 2

1950, 5., 6.

1951, 6., 8.

 

The real file has more columns and rows.

 

I want to bring this into tidy format, so that I have a DataFrame that looks
like this:

 

Year, Region, Value

1950, Name of country 1, 5.

1950, Name of country 2, 6.

1951, Name of country 1, 6.

1951, Name of country 2, 8.

 

Right now I read the file with readtable into a DataFrame and then use

 

melt(df, :Year)

 

This gives me the right structure, but now all the country names are messed
up, e.g. they look like "Name_of_country_1" instead of "Name of country 1".

 

I understand why that is the case, i.e. readtable converts strings into
symbols and has to insert these underscores, but I'm wondering whether the
original string value is preserved somewhere, and could be used in the melt
operation in some way?

 

Thanks,

David

 

--

David Anthoff

University of California, Berkeley

 

http://www.david-anthoff.com

 

Reply via email to