Actually, I'm not certain that your "c" below is what you want, because class(c[1,1]) is "list", and I could not do arithmetic on it. I discovered that when I tried all.equal(c, DF[3:5,]). {Also, "c" is the name of a very useful function; try "?c". It is usually wise to avoid using names of functions for matrices of data.frames. R will select the one you want from the context in most but not all cases.}
hope this helps. spencer graves
Monica Palaseanu-Lovejoy wrote:
Hi Again,
First of all thank you for all the responses to my previous query. Your answers were very helpful and I did the job ;-). Now I hope you can answer as quick the following (sorry I am invading you with trivial questions):
Let’s use again the following data.frame example: DF <- data.frame(x=rnorm(5), y=rnorm(5))
I want to obtain a new data.frame (or matrix) that contains only n rows (from the i rows DF has), and all the columns. If I have to do it step by step I would do something like that, for example:
a3 <- DF[3,] a4 <- DF[4,] a5 <- DF[5,] b <- data.frame(a3, a4, a5) c <- matrix(b, nrow=3, ncol=2, byrow=TRUE)
Now I want to do the same in one go, so I wrote:
for (i in 3:5) { d[i] <- DF[i,] e <- data.frame(d[i]) f <- matrix(e, ncol=2, nrow=3, byrow=TRUE) }
Which of course gives me errors and the matrix f has all elements equal with DF[5,5]. If I don’t use [i] after d, the resulting f matrix is made up from the DF[5,] elements (which is quite normal since i replaces itself ...). So …. How is this done correctly?
I am really appreciating your time and effort to answer me,
Monica
______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html