If you really want a loop, then do: > df=data.frame(x=c(3,6,7),y=c(2,7,4)) > new.list <- list() > for (i in names(df)){ + new.list[[i]] <- df[[i]] + } > > new.list $x [1] 3 6 7
$y [1] 2 7 4 On Tue, Nov 10, 2009 at 8:12 AM, Grzes <gregori...@gmail.com> wrote: > > Thanks jholtman for advice but I need do it using a loop. (Because my code > is a little more complicated). > > > > jholtman wrote: >> >> Is this what you want: >> >>> df=data.frame(x=c(3,6,7),y=c(2,7,4)) >>> df >> x y >> 1 3 2 >> 2 6 7 >> 3 7 4 >>> as.list(df) >> $x >> [1] 3 6 7 >> >> $y >> [1] 2 7 4 >> >> >> On Tue, Nov 10, 2009 at 6:05 AM, Grzes <gregori...@gmail.com> wrote: >>> >>> Hi, >>> I have got a data frame: >>> >>> df=data.frame(x=c(3,6,7),y=c(2,7,4)) >>> >>> and I would like to write my values from data frame to list using loop, >>> for >>> example: >>> >>> lista=list() >>> for (i in 1: length(?)){ >>> lista[[?]][?] = df [?] >>> } >>> But I havn't got any idea what I should put in places where I put a >>> question >>> mark? >>> >>> As a rusult I would like to get a list like this: >>> list: >>> [[1]] >>> 3,6,7 >>> [[2]] >>> 2,7,4 >>> >>> I wll be very happy if somebody can help me >>> >>> >>> -- >>> View this message in context: >>> http://old.nabble.com/write-data-frame-in-a-list-tp26281645p26281645.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> 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. >>> >> >> >> >> -- >> Jim Holtman >> Cincinnati, OH >> +1 513 646 9390 >> >> What is the problem that you are trying to solve? >> >> ______________________________________________ >> R-help@r-project.org mailing list >> 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. >> >> > > -- > View this message in context: > http://old.nabble.com/write-data-frame-in-a-list-tp26281645p26283178.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@r-project.org mailing list 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.