2016-05-01 76 views
0

我下載了課程講稿的CSV文件。具體來說,我下載的數據爲固定速度攝像機從https://data.baltimorecity.gov/Transportation/Baltimore-Fixed-Speed-Cameras/dz54-2aru將CSV文件讀取爲亂碼

該網站提供的CSV格式整齊的數據。 excel數據看起來很好。但是,當我讀到R,通過read.table我得到亂碼,如:

 1. http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd> 
    2 <!--[if IE 8]> 
    3  <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en lang=en 
    4   xmlns:v=urn:schemas-microsoft-com:vml 
    5   xmlns:og=http://opengraphprotocol.org/schema/ class=ie ie8 noBorderRadius noLinearGradient noCss3><![endif]--> 
    6 <!--[if gte IE 9]> 
    7  <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en 
    8   xmlns:v=urn:schemas-microsoft-com:vml 
    9   xmlns:og=http://opengraphprotocol.org/schema/ lang=en class=ie><!  
[endif]--> 
    10 <!--[if !IE]>--> 
    11 <html xmlns=http://www.w3.org/1999/xhtml xml:lang=en lang=en 

我哪裏出錯了?

回答

1

因爲您沒有發佈您的代碼,所以很難確定您錯誤的位置,但看起來您嘗試打開一個xml文件,而不是csv。我從你列出的網站上下載了「Baltimore_Fixed_Speed_Cameras.csv」。導出爲簡單的CSV。然後將下面的代碼工作將其導入到R:

data <- read.csv("Baltimore_Fixed_Speed_Cameras.csv", header=T) 

> head(data) 
         address direction  street crossStreet    intersection      Location.1 
1  S CATON AVE & BENSON AVE  N/B Caton Ave Benson Ave  Caton Ave & Benson Ave (39.2693779962, -76.6688185297) 
2  S CATON AVE & BENSON AVE  S/B Caton Ave Benson Ave  Caton Ave & Benson Ave (39.2693157898, -76.6689698176) 
3 WILKENS AVE & PINE HEIGHTS AVE  E/B Wilkens Ave Pine Heights Wilkens Ave & Pine Heights (39.2720252302, -76.676960806) 
4  THE ALAMEDA & E 33RD ST  S/B The Alameda  33rd St  The Alameda & 33rd St (39.3285013141, -76.5953545714) 
5  E 33RD ST & THE ALAMEDA  E/B  E 33rd The Alameda  E 33rd & The Alameda (39.3283410623, -76.5953594625) 
6  ERDMAN AVE & N MACON ST  E/B  Erdman  Macon St   Erdman & Macon St (39.3068045671, -76.5593167803) 

在純文本編輯器中打開文件了,以確保它真的只是一個香草csv文件。