我想在R中導入一個CSV數據。它是一行數據,並有逗號分隔的條目。數據虛擬提供如下:如何在R中逐字輸入CSV?
Id,SecoId,TertioID,CreateDate,Lat,Long,Duration,Istrue,JournalDate,Post 3232,123,345,30/04/14 2:00,11.726,11.728,5,FALSE,02/04/2014 05:02 +01:00,ABC 3233,124,346,30/04/14 3:00,11.789,11.779,6,TRUE,03/04/2014 06:00 +01:00,BCD
這是一個單行的CSV。如何正確讀取它。 這只是一個虛擬數據集。提供給我的數據集有35個變量和10000個觀察值。任何人都可以向我提供正確的邏輯和相關的代碼。
編輯:所需的輸出是:
Id SecoId TertioID CreateDate Lat Long Duration Istrue JournalDate Post
3232 123 345 30/04/14 2:00 11.726 11.728 5 FALSE 02/04/2014 05:02 +01:00 ABC
3233 124 346 30/04/14 3:00 11.789 11.779 6 TRUE 03/04/2014 06:00 +01:00 BCD
Logic Thought by me:
1. Count the number of variables in the dataset.
2. read the file word by word.
3. Store the values between "," in a cell of the table, and doesnot alter the spaces between the values i.e. in CreateDate value it accepts "30/04/14 2:00" as a single value.
4. the loop runs until the last variable is encountered. and when the loop ends the new row is created and observation is stored from there.
雖然我不能成功地創建一個相關的代碼。
如果在R中逐字逐句閱讀,那麼誰能幫我解決相關問題?
你應該可以通過逐行讀取來達到你想要的效果,這是'read.csv()'的默認行爲。 –
請閱讀編輯@TimBiegeleisen –