[R] Convert list to data frame

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Sat Feb 27 18:50:51 CET 2016


I think the advice about the file format is an track, but you imply modifying the file as a solution but that is probably not the best approach. Using a decent text editor that shows you what invisible characters are in the file can guide you in adjusting the arguments to read.table. for example,  the OP specified tab separators between fields, as Excel might put between fields in a text file. However, that is not a universal standard for text files so if spaces are used then removing the sep argument from the read.table call might help. 
-- 
Sent from my phone. Please excuse my brevity.

On February 27, 2016 7:52:06 AM PST, Karim Mezhoud <kmezhoud at gmail.com> wrote:
>To known the format of your object, please use
>class(Data)
>str(Data)
>
>Be sure to have regular space between strings in your file.txt.
>Karim
>
>On Sat, Feb 27, 2016 at 3:56 PM, Ivan Calandra
><ivan.calandra at univ-reims.fr>
>wrote:
>
>> Hi,
>>
>> I have seen this question a few days/weeks ago...
>>
>> Data.frames are special list, so it's normal.
>> Read the help for read.table(), especially the "value" section (where
>the
>> output of the function is described). And read also some introductory
>> material, where the different data types are explained.
>>
>> HTH,
>> Ivan
>>
>> --
>> Ivan Calandra, PhD
>> University of Reims Champagne-Ardenne
>> GEGENAA - EA 3795
>> CREA - 2 esplanade Roland Garros
>> 51100 Reims, France
>> +33(0)3 26 77 36 89
>> ivan.calandra at univ-reims.fr
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>>
>> Le 27/02/2016 15:04, asma.rabe at gmail.com a écrit :
>>
>>> Hi,
>>>
>>> I  read data from file as follows
>>>
>>> Data<-read.table("file.txt",header=T,sep="\t")
>>>
>>> mode(Data)
>>> list
>>>
>>> I want to convert data to data frame, I tried the following:
>>>
>>> as.data.frame(Data)
>>> data.frame(Data)
>>>
>>> But the Data did not change
>>>
>>> When I tried
>>> as.data.frame(unlist(Data))
>>>
>>> The Data converted to a vector not to a data frame. Any idea ?
>>>
>>> Thank you in advance
>>>
>>>
>>> Sent from my iPhone
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

	[[alternative HTML version deleted]]



More information about the R-help mailing list