Skip to content
Prev 18568 / 398498 Next

changing the form of a list

On Mon, 8 Apr 2002, jimi adams wrote:

            
Suppose the matrix is actually a data.frame (if it isn't, use
as.data.frame) called df with columns called i and x

tapply(df$x, df$i, c)
i  x
1  1  1
2  2  2
3  3  3
4  3  4
5  4  5
6  2  6
7  1  7
8  3  8
9  4  9
10 3 10
$"1"
[1] 1 7

$"2"
[1] 2 6

$"3"
[1]  3  4  8 10

$"4"
[1] 5 9

Or by()
df$i: 1
[1] 1 7
------------------------------------------------------------
df$i: 2
[1] 2 6
------------------------------------------------------------
df$i: 3
[1]  3  4  8 10
------------------------------------------------------------
df$i: 4
[1] 5 9

Or you might want to leave the data in its current form and use tapply()
or by() to do whatever it is you want to do with it.

	-thomas




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._