[R] How to iterate dataframe within a hash

stephen sefick ssefick at gmail.com
Wed Dec 17 03:45:38 CET 2008


I don't know if this is what you want, but it seems that you just want
to print a subset of your columns:

testlib$tags[,c("tag", "count.raw", "count.adj")]

if you want to do something other than just "print" the columns then
look at the apply family of functions.


On Tue, Dec 16, 2008 at 9:02 PM, Gundala Viswanath <gundalav at gmail.com> wrote:
> Dear all,
>
> I have the following data structure
>
>> print(testlib)
> $tags
>             tag            count.raw  count.adj  err
> 1     aaaaaaaaaa        94         93             0.5
> 2     aaaaaaaaac         1           2               0.2
> 3     aaaaaaaaag         3           2               0.1
> 4     aaaaaaaaca         1           1               0.003
>
>
> I want to iterate the data above and print only
> "tag", "count.raw" and "count.adj" column.
>
> Why my script below failed to do the task?
>
>
> for (i in 1:nrow(testlib)) {
>   cat(testlib$tags[["count.tag"]],",", testlib$tags[["count.raw"]],
> ",", testlib$tags[["count.adj"]],"\n")
> }
>
>
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> R-help at 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.
>



-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

								-K. Mullis



More information about the R-help mailing list