Getting list from row R

86 views Asked by At

I have file, when u can check here: http://www.nbp.pl/kursy/Archiwum/archiwum_tab_a_1999.xls

I want to get first row of this file into list. When I do this:

dane <- read.xls("http://www.nbp.pl/kursy/Archiwum/archiwum_tab_a_1999.xls")
names(dane)

I recieved list but some weird values like X1, X2. I want list of this elements: Nr / No. Data / Date 1 USD 1 EUR 1 AUD etc.

EDIT:

result of dput(dane):

http://pastebin.com/5YZwMx6a

EDIT 2:

result of names(dane):

[1] "X"                               "X.1"                            
[3] "W.A.L.U.T.A.....C.U.R.R.E.N.C.Y" "X.2"                            
[5] "X.3"                             "X.4"                            
[7] "X.5"                             "X.6"                            
[9] "X.7"                             "X.8"                            
[11] "X.9"                             "X.10"                           
[13] "X.11"                            "X.12"                           
[15] "X.13"                            "X.14"                           
[17] "X.15"                            "X.16"                           
[19] "X.17"                            "X.18"                           
[21] "X.19"                            "X.20"                           
[23] "X.21"                            "X.22"    
2

There are 2 answers

0
IRTFM On BEST ANSWER

The problem is that you have your first row as a bunch of merged cells. You should try with an edited version that deletes the first row.enter image description here

It wasn't clear to me that read.xls would honor a request to skip lines but it does, so this succeeds:

> input <- gdata::read.xls("~/Downloads/archiwum_tab_a_1999.xls", skip=1)
> str(input)
'data.frame':   254 obs. of  28 variables:
 $ Nr...No.   : int  1 2 3 4 5 6 7 8 9 10 ...
 $ Data...Date: Factor w/ 254 levels "1999-01-01","1999-01-04",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ X1.USD     : num  3.5 3.45 3.41 3.41 3.46 ...
 $ X1.EUR     : num  4.09 4.07 4.02 4.01 4.02 ...
 $ X1.AUD     : num  2.15 2.13 2.12 2.13 2.17 ...
 $ X1.ATS     : num  0.297 0.296 0.292 0.291 0.292 ...
 $ X100.BEF   : num  10.14 10.08 9.98 9.94 9.96 ...
 $ X1.CZK     : num  0.117 0.116 0.115 0.115 0.115 ...
 $ X1.DKK     : num  0.548 0.546 0.54 0.538 0.54 ...
 $ X1.FIM     : num  0.688 0.684 0.677 0.674 0.676 ...
 $ X1.FRF     : num  0.624 0.62 0.614 0.611 0.613 ...
 $ X100.GRD   : num  1.25 1.25 1.24 1.23 1.24 ...
 $ X100.ESP   : num  2.46 2.44 2.42 2.41 2.42 ...
 $ X1.NLG     : num  1.86 1.85 1.83 1.82 1.82 ...
 $ X1.IEP     : num  5.2 5.16 5.11 5.09 5.1 ...
 $ X100.JPY   : num  3.09 3.04 3.06 3.05 3.11 ...
 $ X1.CAD     : num  2.29 2.26 2.24 2.26 2.28 ...
 $ X100.LUF   : num  10.14 10.08 9.98 9.94 9.96 ...
 $ X1.NOK     : num  0.461 0.459 0.458 0.459 0.466 ...
 $ X100.PTE   : num  2.04 2.03 2.01 2 2 ...
 $ X1.DEM     : num  2.09 2.08 2.06 2.05 2.06 ...
 $ X1.CHF     : num  2.55 2.52 2.49 2.49 2.49 ...
 $ X1.SEK     : num  0.431 0.429 0.428 0.431 0.438 ...
 $ X100.HUF   : num  1.62 1.62 1.6 1.6 1.61 ...
 $ X1.GBP     : num  5.76 5.72 5.65 5.67 5.7 ...
 $ X100.ITL   : num  0.211 0.21 0.208 0.207 0.208 ...
 $ X1.XDR     : num  4.93 4.86 4.81 4.83 4.84 ...
 $ X          : logi  NA NA NA NA NA NA ...
0
Steven Beaupré On

That's because your file's first row is: "W a l u t a / C u r r e n c y". Your actual column names are in the second row.

You could download the file first and then read it in using:

library(readxl)
dane <- read_excel("archiwum_tab_a_1999.xls", skip = 1)

This will skip the first row and you'll get proper column names:

> colnames(dane)
 [1] "Nr / No."    "Data / Date" "1 USD"       "1 EUR"       "1 AUD"       "1 ATS"       "100 BEF"     "1 CZK"      
 [9] "1 DKK"       "1 FIM"       "1 FRF"       "100 GRD"     "100 ESP"     "1 NLG"       "1 IEP"       "100 JPY"    
[17] "1 CAD"       "100 LUF"     "1 NOK"       "100 PTE"     "1 DEM"       "1 CHF"       "1 SEK"       "100 HUF"    
[25] "1 GBP"       "100 ITL"     "1 XDR"