[R] A basic design question for R
Onur Uncu
onuruncu at gmail.com
Sat Jun 16 20:35:39 CEST 2012
Thank you all for the useful replies. I will go with the list of
matrices idea as suggested multiple times.
On Sat, Jun 16, 2012 at 6:50 PM, Jeff Newmiller
<jdnewmil at dcn.davis.ca.us> wrote:
> A data frame is a list of vectors all with the same length. Note that vectors have simple types. Sticking other types of objects into it violates the generic constraint stated above, leading to incompatibility with many functions that normally work with data frames.
>
> If you want to maintain data frame semantics for your original data, possibilities I see right off.
>
> 1) Make a list with two elements... the first being the original data frame, and the second being a list of matrices of the same length as the nrows of the data frame, maintaining index correspondence.
>
> 2) Represent the list of matrices as a single data frame, with one column that identifies the row in the original data frame for each row of the mortality matrix. This is a more relational (as in SQL) solution.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
>
>
>
>
>
>
> Onur Uncu <onuruncu at gmail.com> wrote:
>
>>Thank you. But isn't a data frame already a list? What is wrong with
>>adding a column to the existing data frame (a column with the
>>mortality curve matrices)?
>>
>>Sorry if I am being difficult. Just want to learn good design in R.
>>
>>
>>On Sat, Jun 16, 2012 at 5:49 PM, steven mosher <moshersteven at gmail.com>
>>wrote:
>>> use a list. or create new class which is a list
>>>
>>> On Jun 16, 2012 8:52 AM, "Onur Uncu" <onuruncu at gmail.com> wrote:
>>>>
>>>> Hello R Community,
>>>>
>>>> I have the following design question. I have a data set that looks
>>>> like this (shortened for the sake of example).
>>>>
>>>> Gender Age
>>>> M 70
>>>> F 65
>>>> M 70
>>>>
>>>> Each row represents a person with an age/gender combination. We
>>could
>>>> put this data into a data frame.
>>>>
>>>> Now, I would like to do some actuarial analysis on this data set. To
>>>> do so, I need to create and store a mortality curve for each person
>>in
>>>> the table (a mortality curve is a matrix with 2 columns: date and
>>>> survival probability). I can write a function that returns a
>>mortality
>>>> curve given gender and age. The question is the following: In what
>>>> data format should I store all these mortality curve objects? Should
>>I
>>>> add a column to the data frame and each entry in that column is a
>>>> matrix (a mortality curve)? This way, the mortality curve would be
>>>> stored next to age/gender data in the data frame. However, I read in
>>>> several places that putting vectors/matrices as elements of a data
>>>> frame is a bad idea. I do not know why. What is a good design choice
>>>> in this instance please? How should I store the mortality curves?
>>>>
>>>> Thank you for your help.
>>>>
>>>> ______________________________________________
>>>> 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.
>>
>>______________________________________________
>>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.
>
More information about the R-help
mailing list