我想在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 –