[R] Convert list to data frame
David Winsemius
dwinsemius at comcast.net
Sat Feb 27 18:27:40 CET 2016
> 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 change
R 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
More information about the R-help
mailing list