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
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. >
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]]
> On Feb 27, 2016, at 6:04 AM, <asma.rabe at gmail.com> <asma.rabe at gmail.com> wrote: > > 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,It is already a dataframe. That is the class of object that read.table returns.> I tried the following: > > as.data.frame(Data) > data.frame(Data) > > But the Data did not changeR is a functional language. Simply applying a function does NOT alter the value of the arguments. Need to use assignment. If Data had not been a dataframe already and it had been a list with values whose lengths were equal, then you would have needed to perform: Data <- data.frame(Data)> > When I tried > as.data.frame(unlist(Data)) > > The Data converted to a vector not to a data frame. Any idea ? > >David Winsemius Alameda, CA, USA