I think it will depend on how you plan to use the data. Again in my
opinion, I think the simplest most natural storage structure in the
context of R would be a nested list:
mydat <- list(
list(contacts=c(3,4), ncon=2),
list(contacts=c(1,3,4), ncon=3),
list(contacts=c(4,2,1), ncon=3),
list(contacts=1, ncon=1)
)
## if the id values are not sequential integers, then you would also need
names(mydat) <- {whatever the id values are}
Depending on subsequent processing, it might not be necessary to store the
number of contacts, because it can easily be calculated whenever needed.
In which case the structure could be simpler:
mydat <- list( c(3,4), c(1,3,4), c(4,2,1), 1 )
names(mydat) <- {whatever the id values are}
Even though a data frame can be used, as Duncan and arun have shown, a
data frame does not seem natural to me, given that the number of contacts
is not the same for all ids.
It may also depend on where the data is coming from and how much there is
of it.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
On 5/10/14 4:46 AM, "Ragia Ibrahim" <ragia11 at hotmail.com>
wrote:
>Dear Group,
>I have data like the following
>
>id contacts_list number of contacts
>---------------------------------------------------
>1 3 4 2
>2 1 3 4 3
>3 4 2 1 3
>4 1 1
>------------------------------------------------------
>
>
>can you kindly please sugest a data type in R to use for it?
>i thought about data frame that consists of a list element. but lists
>are not in the same length, any solutions?
>thanks in advance
>RAE
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>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.