[R] Indexing Elements of a Dataframe

Wolfgang Viechtbauer wviechtb at s.psych.uiuc.edu
Tue May 28 20:40:13 CEST 2002


Hello List-Members,

Let's say that I have the following code:

for (i in c(10, 20, 30)) {
  for (j in c(200, 400, 600)) {
    ...
    ...
    x <- "something"
    * (code here)
  }
}

* Now, x is some result that I want to put into a results "matrix" that
looks like this:

   200 400 600
10
20
30

I came up with an ad-hoc solution adding some counters (called "ro" and
"co") and using a matrix for the results, which I could index with those
counters (results[ro,co] <- x) and then converting that matrix into a
dataframe and changing the row and column names. That seems a little too
convoluted.

I tried to come up with a "neater" solution, trying to create a
dataframe that looks like the one above and then indexing the fields in
the dataframe by results$i[j] but I couldn't get it to work. Is there a
way of doing this or maybe a better solution?

Thanks in advance!

Wolfgang

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list