[R] vector entry in matix
jwiley.psych at gmail.com
Thu Jul 5 22:25:30 CEST 2012
This is non trivial to do, but if you will be working with this sort
of data and are inclined to do some programming, you might consider
creating a new class. S4 classes and methods are quite flexible, and
you can allow them to lean on or inherit from existing classes such as
matrices. For example, your class might consist of three lists and a
data frame. The length of each list would be forced to be equal to
the number of rows in the data frame. Each element of each list would
support a length 2 numeric vector (or integer vector or whatever it is
you need). THe lists then would hold nodes 1 - 3, and the data frame
would hold other information. You can similarly write methods so that
for your special class,
d[1, 1] would return c(x1, y1), essentially you create a mix of lists
and a matrix with all the necessary constraints, and you develop
methods that allow you to operate on this in a way that is sensible
for your data.
This is stab in the dark, but if you happen to be dealing with social
network style data, (triangles and neighbors make me think of that),
you should investigate existing packages for that as they may already
have their own classes/have a way they expect data to be structured.
Off the top of my head, the package "sna" comes to mind as a starting
place to look (though I am not personally very familiar with it).
On Thu, Jul 5, 2012 at 9:37 AM, Thomas C. <thomas.csapak at gmail.com> wrote:
> well thank you, i think we get closer to my problem. but i meant it in a
> different way. maybe i describe what i intended to do:
> i have number of triangles which i'd like to store in a list, matrix,...etc.
> i thought it could look sth. like that:
> triangle node1 node2 node3 .....
> 1 c(x1,y1) c(x2,y3) c(x3,y3)
> 1 c(x4,y4) c(x5,y5) c(x6,y6)
> i know that i could just make more rows for the x/y values but the problem
> is, that i need to store more than these properties (say the neighbours of
> these nodes and their coordinates) and i thought it would be more convenient
> to save these as vectors. it was just a thought... is this possible?
> View this message in context: http://r.789695.n4.nabble.com/vector-entry-in-matix-tp4635478p4635509.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
More information about the R-help