value.labels

classic Classic list List threaded Threaded
20 messages Options
Reply | Threaded
Open this post in threaded view
|

value.labels

zcatav
Hello R people,

I have a "data.frame". Status variable has 3 values. 0->alive, 1->dead and 2->missed
Status as a factor have correct levels. Levels and labels output as follows;

levels(Adbf$status); labels(Adbf$status)
[1] "0" "1" "2"
  [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"
 [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"
 [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"
 [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"
 [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"
 ........................................................................"644"

Can i add value.labels to status variable? If yes how? Can i see these value.labels on results or graphics?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Uwe Ligges-3


On 11.08.2011 16:10, zcatav wrote:

> Hello R people,
>
> I have a "data.frame". Status variable has 3 values. 0->alive, 1->dead and
> 2->missed
> Status as a factor have correct levels. Levels and labels output as follows;
>
> levels(Adbf$status); labels(Adbf$status)
> [1] "0" "1" "2"
>    [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"
>   [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"
>   [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"
>   [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"
>   [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"
>
> ........................................................................"644"
>
> Can i add value.labels to status variable? If yes how? Can i see these
> value.labels on results or graphics?


levels(Adbf$status) <- c("alive", "dead", "missed")

Uwe Ligges


> Thanks.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/value-labels-tp3735947p3735947.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

David Winsemius

On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:

>
>
> On 11.08.2011 16:10, zcatav wrote:
>> Hello R people,
>>
>> I have a "data.frame". Status variable has 3 values. 0->alive, 1-
>> >dead and
>> 2->missed
>> Status as a factor have correct levels. Levels and labels output as  
>> follows;
>>
>> levels(Adbf$status); labels(Adbf$status)
>> [1] "0" "1" "2"
>>   [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"
>>  [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"
>>  [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"
>>  [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"
>>  [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"
>>
>> ........................................................................"644
>> "
>>
>> Can i add value.labels to status variable? If yes how? Can i see  
>> these
>> value.labels on results or graphics?
>
>
> levels(Adbf$status) <- c("alive", "dead", "missed")

I'm probably making some mistake, but my efforts to use something  
similar to that construction have caused me to "destroy" variables in  
the sense that I have made them all NA's. My more (defensive?,  
unnecessary?)  practice has become:

  Adbf$status <- factor( Adbf$status, labels= c("alive", "dead",  
"missed") )

When I try to use the `levels<-' operation now on what I think is a  
similar object, I get an error but maybe that relates to the fact that  
levels and labels are different?

 > status <- factor( sample(1:50, 400, replace=TRUE)  )
 > status <- status[status %in% c("1", "2", "3")]
 > str(status)
  Factor w/ 50 levels "1","2","3","4",..: 3 3 1 1 2 2 2 2 1 1 ...
 > length(status)
[1] 24
 > levels(status) <- c("alive", "dead", "missed")
Error in `levels<-.factor`(`*tmp*`, value = c("alive", "dead",  
"missed" :
   number of levels differs

The real question I have as a follow-on is what is the "right way" to  
take an object like this:

levels(testres) <- c(levels(testres), "NotDone")
 > testres
[1] 1    2    3    <NA>
Levels: 1 2 3 NotDone

... and add a not done label?

These do not "work":
#1:
 > levels(testres) <- c("NotDone", levels(testres))
 > testres[4]
[1] <NA>
Levels: NotDone 1 2 3

#2:
 > testres <- factor(c(1,2,3,NA))
 > levels(testres) <- c(levels(testres), "NotDone")
 > testres[4]
[1] <NA>
Levels: 1 2 3 NotDone

I have been converting to numeric, changing NA to 0 and then  
refactoring with labels=c("Not done", levels(old_factor) ), but that  
seems B(a)roke.


--

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Uwe Ligges-3


On 11.08.2011 19:22, David Winsemius wrote:

>
> On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>
>>
>>
>> On 11.08.2011 16:10, zcatav wrote:
>>> Hello R people,
>>>
>>> I have a "data.frame". Status variable has 3 values. 0->alive,
>>> 1->dead and
>>> 2->missed
>>> Status as a factor have correct levels. Levels and labels output as
>>> follows;
>>>
>>> levels(Adbf$status); labels(Adbf$status)
>>> [1] "0" "1" "2"
>>> [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
>>> [11] "11" "12" "13" "14" "15" "16" "17" "18" "19" "20"
>>> [21] "21" "22" "23" "24" "25" "26" "27" "28" "29" "30"
>>> [31] "31" "32" "33" "34" "35" "36" "37" "38" "39" "40"
>>> [41] "41" "42" "43" "44" "45" "46" "47" "48" "49" "50"
>>>
>>> ........................................................................"644"
>>>
>>>
>>> Can i add value.labels to status variable? If yes how? Can i see these
>>> value.labels on results or graphics?
>>
>>
>> levels(Adbf$status) <- c("alive", "dead", "missed")
>
> I'm probably making some mistake, but my efforts to use something
> similar to that construction have caused me to "destroy" variables in
> the sense that I have made them all NA's. My more (defensive?,
> unnecessary?) practice has become:
>
> Adbf$status <- factor( Adbf$status, labels= c("alive", "dead", "missed") )
>
> When I try to use the `levels<-' operation now on what I think is a
> similar object, I get an error but maybe that relates to the fact that
> levels and labels are different?
>
>  > status <- factor( sample(1:50, 400, replace=TRUE) )
>  > status <- status[status %in% c("1", "2", "3")]
>  > str(status)
> Factor w/ 50 levels "1","2","3","4",..: 3 3 1 1 2 2 2 2 1 1 ...

Errr, this should have 3 levels, "0", "1", "2", actually.

>  > length(status)
> [1] 24
>  > levels(status) <- c("alive", "dead", "missed")
> Error in `levels<-.factor`(`*tmp*`, value = c("alive", "dead", "missed" :
> number of levels differs
>
> The real question I have as a follow-on is what is the "right way" to
> take an object like this:
>
> levels(testres) <- c(levels(testres), "NotDone")
>  > testres
> [1] 1 2 3 <NA>
> Levels: 1 2 3 NotDone
>
> ... and add a not done label?
>
> These do not "work":
> #1:
>  > levels(testres) <- c("NotDone", levels(testres))
>  > testres[4]
> [1] <NA>
> Levels: NotDone 1 2 3
>
> #2:
>  > testres <- factor(c(1,2,3,NA))
>  > levels(testres) <- c(levels(testres), "NotDone")
>  > testres[4]
> [1] <NA>
> Levels: 1 2 3 NotDone
>
> I have been converting to numeric, changing NA to 0 and then refactoring
> with labels=c("Not done", levels(old_factor) ), but that seems B(a)roke.

Hmm, when you want to add a level without changing the class of the
factor object, you will have to add the level at first and then assign
the level to the elements of the object. I'd probably rebuild the whole
thing in that case.

As I understood the question, just how to rename the levels was the
original question.

Uwe

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

zcatav
Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:

>
> On 11.08.2011 19:22, David Winsemius wrote:
> >
> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >
> >>
> >>
> >> On 11.08.2011 16:10, zcatav wrote:
> >>> Hello R people,
> >>>
> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> >>> 1->dead and
> >>> 2->missed..........................
> .........................................
> As I understood the question, just how to rename the levels was the
> original question.
>
> Uwe
I don't want to rename levels or converting from numeric to string. I
want to add each corresponding levels value, a label, as in SPSS.
Level 0 labeled with alive,
level 1 labeled with dead and
level 2 labeled with missed.



--
Zeki Çatav

______________________________________________
[hidden email] 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.

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Bert Gunter
Use factor -- puhleeze read the Help file therefor:

factor(x = character(), levels, labels = levels,
       exclude = NA, ordered = is.ordered(x))

either an optional vector of labels for the levels (in the same order
as levels after removing those in exclude), or a character string of
length 1.

-- Bert

2011/8/11 Zeki Çatav <[hidden email]>:

> Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>>
>> On 11.08.2011 19:22, David Winsemius wrote:
>> >
>> > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>> >
>> >>
>> >>
>> >> On 11.08.2011 16:10, zcatav wrote:
>> >>> Hello R people,
>> >>>
>> >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>> >>> 1->dead and
>> >>> 2->missed..........................
>> .........................................
>> As I understood the question, just how to rename the levels was the
>> original question.
>>
>> Uwe
>
> I don't want to rename levels or converting from numeric to string. I
> want to add each corresponding levels value, a label, as in SPSS.
> Level 0 labeled with alive,
> level 1 labeled with dead and
> level 2 labeled with missed.
>
>
>
> --
> Zeki Çatav
>
> ______________________________________________
> [hidden email] 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.
>
>



--
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Heinz Tuechler
In reply to this post by zcatav
At 11.08.2011 21:50 +0300, Zeki Çatav wrote:

>Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
> >
> > On 11.08.2011 19:22, David Winsemius wrote:
> > >
> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> > >
> > >>
> > >>
> > >> On 11.08.2011 16:10, zcatav wrote:
> > >>> Hello R people,
> > >>>
> > >>> I have a "data.frame". Status variable has 3 values. 0->alive,
> > >>> 1->dead and
> > >>> 2->missed..........................
> > .........................................
> > As I understood the question, just how to rename the levels was the
> > original question.
> >
> > Uwe
>
>I don't want to rename levels or converting from numeric to string. I
>want to add each corresponding levels value, a label, as in SPSS.
>Level 0 labeled with alive,
>level 1 labeled with dead and
>level 2 labeled with missed.

This is not possible with a factor, because
factor levels can only be positive integers.

Heinz



>--
>Zeki Çatav
>
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Rolf Turner-3
On 12/08/11 09:59, Heinz Tuechler wrote:

> At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
>> Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>> >
>> > On 11.08.2011 19:22, David Winsemius wrote:
>> > >
>> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>> > >
>> > >>
>> > >>
>> > >> On 11.08.2011 16:10, zcatav wrote:
>> > >>> Hello R people,
>> > >>>
>> > >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>> > >>> 1->dead and
>> > >>> 2->missed..........................
>> > .........................................
>> > As I understood the question, just how to rename the levels was the
>> > original question.
>> >
>> > Uwe
>>
>> I don't want to rename levels or converting from numeric to string. I
>> want to add each corresponding levels value, a label, as in SPSS.
>> Level 0 labeled with alive,
>> level 1 labeled with dead and
>> level 2 labeled with missed.
>
> This is not possible with a factor, because factor levels can only be
> positive integers.

That is just plain (ridiculously) wrong. RTFM.

cheers,

Rolf Turner

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Heinz Tuechler
At 12.08.2011 09:11 +1200, Rolf Turner wrote:

>On 12/08/11 09:59, Heinz Tuechler wrote:
>>At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
>>>Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>>> >
>>> > On 11.08.2011 19:22, David Winsemius wrote:
>>> > >
>>> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>>> > >
>>> > >>
>>> > >>
>>> > >> On 11.08.2011 16:10, zcatav wrote:
>>> > >>> Hello R people,
>>> > >>>
>>> > >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>>> > >>> 1->dead and
>>> > >>> 2->missed..........................
>>> > .........................................
>>> > As I understood the question, just how to rename the levels was the
>>> > original question.
>>> >
>>> > Uwe
>>>
>>>I don't want to rename levels or converting from numeric to string. I
>>>want to add each corresponding levels value, a label, as in SPSS.
>>>Level 0 labeled with alive,
>>>level 1 labeled with dead and
>>>level 2 labeled with missed.
>>
>>This is not possible with a factor, because
>>factor levels can only be positive integers.
>
>That is just plain (ridiculously) wrong. RTFM.
>
>cheers,
>
>Rolf Turner

So, how would you construct a factor with levels
0, 1, 2 and labels alive, dead, and missed, as the original post asked for?

Heinz

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Rolf Turner-3
In reply to this post by Rolf Turner-3
On 12/08/11 11:34, Heinz Tuechler wrote:

> At 12.08.2011 09:11 +1200, Rolf Turner wrote:
>> On 12/08/11 09:59, Heinz Tuechler wrote:
>>> At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
>>>> Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>>>> >
>>>> > On 11.08.2011 19:22, David Winsemius wrote:
>>>> > >
>>>> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>>>> > >
>>>> > >>
>>>> > >>
>>>> > >> On 11.08.2011 16:10, zcatav wrote:
>>>> > >>> Hello R people,
>>>> > >>>
>>>> > >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>>>> > >>> 1->dead and
>>>> > >>> 2->missed..........................
>>>> > .........................................
>>>> > As I understood the question, just how to rename the levels was the
>>>> > original question.
>>>> >
>>>> > Uwe
>>>>
>>>> I don't want to rename levels or converting from numeric to string. I
>>>> want to add each corresponding levels value, a label, as in SPSS.
>>>> Level 0 labeled with alive,
>>>> level 1 labeled with dead and
>>>> level 2 labeled with missed.
>>>
>>> This is not possible with a factor, because factor levels can only
>>> be positive integers.
>>
>> That is just plain (ridiculously) wrong. RTFM.
>>
>> cheers,
>>
>> Rolf Turner
>
> So, how would you construct a factor with levels 0, 1, 2 and labels
> alive, dead, and missed, as the original post asked for?
>
> Heinz

As I said, RTFM. But for completeness:

x <- sample(0:2,100,TRUE)
y <- factor(x,labels=c("alive","dead","missed"))

Duhhh.

cheers,

Rolf Turner

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Heinz Tuechler
At 12.08.2011 11:05 +1200, Rolf Turner wrote:

>On 12/08/11 11:34, Heinz Tuechler wrote:
>>At 12.08.2011 09:11 +1200, Rolf Turner wrote:
>>>On 12/08/11 09:59, Heinz Tuechler wrote:
>>>>At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
>>>>>Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>>>>> >
>>>>> > On 11.08.2011 19:22, David Winsemius wrote:
>>>>> > >
>>>>> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>>>>> > >
>>>>> > >>
>>>>> > >>
>>>>> > >> On 11.08.2011 16:10, zcatav wrote:
>>>>> > >>> Hello R people,
>>>>> > >>>
>>>>> > >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>>>>> > >>> 1->dead and
>>>>> > >>> 2->missed..........................
>>>>> > .........................................
>>>>> > As I understood the question, just how to rename the levels was the
>>>>> > original question.
>>>>> >
>>>>> > Uwe
>>>>>
>>>>>I don't want to rename levels or converting from numeric to string. I
>>>>>want to add each corresponding levels value, a label, as in SPSS.
>>>>>Level 0 labeled with alive,
>>>>>level 1 labeled with dead and
>>>>>level 2 labeled with missed.
>>>>
>>>>This is not possible with a factor, because
>>>>factor levels can only be positive integers.
>>>
>>>That is just plain (ridiculously) wrong. RTFM.
>>>
>>>cheers,
>>>
>>>Rolf Turner
>>
>>So, how would you construct a factor with
>>levels 0, 1, 2 and labels alive, dead, and
>>missed, as the original post asked for?
>>
>>Heinz
>
>As I said, RTFM. But for completeness:
>
>x <- sample(0:2,100,TRUE)
>y <- factor(x,labels=c("alive","dead","missed"))
>
>Duhhh.
>
>cheers,
>
>Rolf Turner

Maybe you would like to look at the structure.

str(y)
Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...

or

dput(y)
structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
), class = "factor")
 >

Anything else but positive integers?

Heinz

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Heinz Tuechler
At 12.08.2011 01:53 +0100, Heinz Tuechler wrote:

>At 12.08.2011 11:05 +1200, Rolf Turner wrote:
>>On 12/08/11 11:34, Heinz Tuechler wrote:
>>>At 12.08.2011 09:11 +1200, Rolf Turner wrote:
>>>>On 12/08/11 09:59, Heinz Tuechler wrote:
>>>>>At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
>>>>>>Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>>>>>> >
>>>>>> > On 11.08.2011 19:22, David Winsemius wrote:
>>>>>> > >
>>>>>> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>>>>>> > >
>>>>>> > >>
>>>>>> > >>
>>>>>> > >> On 11.08.2011 16:10, zcatav wrote:
>>>>>> > >>> Hello R people,
>>>>>> > >>>
>>>>>> > >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>>>>>> > >>> 1->dead and
>>>>>> > >>> 2->missed..........................
>>>>>> > .........................................
>>>>>> > As I understood the question, just how to rename the levels was the
>>>>>> > original question.
>>>>>> >
>>>>>> > Uwe
>>>>>>
>>>>>>I don't want to rename levels or converting from numeric to string. I
>>>>>>want to add each corresponding levels value, a label, as in SPSS.
>>>>>>Level 0 labeled with alive,
>>>>>>level 1 labeled with dead and
>>>>>>level 2 labeled with missed.
>>>>>
>>>>>This is not possible with a factor, because
>>>>>factor levels can only be positive integers.
>>>>
>>>>That is just plain (ridiculously) wrong. RTFM.
>>>>
>>>>cheers,
>>>>
>>>>Rolf Turner
>>>
>>>So, how would you construct a factor with
>>>levels 0, 1, 2 and labels alive, dead, and
>>>missed, as the original post asked for?
>>>
>>>Heinz
>>
>>As I said, RTFM. But for completeness:
>>
>>x <- sample(0:2,100,TRUE)
>>y <- factor(x,labels=c("alive","dead","missed"))
>>
>>Duhhh.
>>
>>cheers,
>>
>>Rolf Turner
>
>Maybe you would like to look at the structure.
>
>str(y)
>Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...
>
>or
>
>dput(y)
>structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
>1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
>1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
>2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
>2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
>3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
>2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
>), class = "factor")
> >
>
>Anything else but positive integers?
>
>Heinz

To be fair, you can construct a factor containing zeros.

b <- c(0L,0L,1L,1L,1L,2L,2L,2L,2L)
 > b
[1] 0 0 1 1 1 2 2 2 2
 > str(b)
  int [1:9] 0 0 1 1 1 2 2 2 2
 > table(b)
b
0 1 2
2 3 4
 > levels(b) <- letters[1:3]
 > str(b)
  atomic [1:9] 0 0 1 1 1 2 2 2 2
  - attr(*, "levels")= chr [1:3] "a" "b" "c"
 > class(b) <- 'factor'
 > str(b)
  Factor w/ 3 levels "a","b","c": 0 0 1 1 1 2 2 2 2

But, if you print it, you get a warning.

 > b
[1] a a a b b b b a a
Levels: a b c
Warning message:
In xx[] <- as.character(x) :
   number of items to replace is not a multiple of replacement length

And table() gives a wrong result.
 > table(b)
b
a b c
3 4 0
 >

If you take a numeric, not explicitly integer vector, you are less lucky.

c <- c(0,0,1,1,1,2,2,2,2)
 > str(c)
  num [1:9] 0 0 1 1 1 2 2 2 2
 > levels(c) <- letters[1:3]
 > str(c)
  atomic [1:9] 0 0 1 1 1 2 2 2 2
  - attr(*, "levels")= chr [1:3] "a" "b" "c"

Assigning class "factor" is rejected with an error.
 > class(c) <- 'factor'
Error in class(c) <- "factor" :
   adding class "factor" to an invalid object
 >

Heinz

>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Rolf Turner-3
In reply to this post by Rolf Turner-3
On 12/08/11 12:53, Heinz Tuechler wrote:

> At 12.08.2011 11:05 +1200, Rolf Turner wrote:
>> On 12/08/11 11:34, Heinz Tuechler wrote:
>>> At 12.08.2011 09:11 +1200, Rolf Turner wrote:
>>>> On 12/08/11 09:59, Heinz Tuechler wrote:
>>>>> At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
>>>>>> Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
>>>>>> >
>>>>>> > On 11.08.2011 19:22, David Winsemius wrote:
>>>>>> > >
>>>>>> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
>>>>>> > >
>>>>>> > >>
>>>>>> > >>
>>>>>> > >> On 11.08.2011 16:10, zcatav wrote:
>>>>>> > >>> Hello R people,
>>>>>> > >>>
>>>>>> > >>> I have a "data.frame". Status variable has 3 values. 0->alive,
>>>>>> > >>> 1->dead and
>>>>>> > >>> 2->missed..........................
>>>>>> > .........................................
>>>>>> > As I understood the question, just how to rename the levels was
>>>>>> the
>>>>>> > original question.
>>>>>> >
>>>>>> > Uwe
>>>>>>
>>>>>> I don't want to rename levels or converting from numeric to
>>>>>> string. I
>>>>>> want to add each corresponding levels value, a label, as in SPSS.
>>>>>> Level 0 labeled with alive,
>>>>>> level 1 labeled with dead and
>>>>>> level 2 labeled with missed.
>>>>>
>>>>> This is not possible with a factor, because factor levels can only
>>>>> be positive integers.
>>>>
>>>> That is just plain (ridiculously) wrong. RTFM.
>>>>
>>>> cheers,
>>>>
>>>> Rolf Turner
>>>
>>> So, how would you construct a factor with levels 0, 1, 2 and labels
>>> alive, dead, and missed, as the original post asked for?
>>>
>>> Heinz
>>
>> As I said, RTFM. But for completeness:
>>
>> x <- sample(0:2,100,TRUE)
>> y <- factor(x,labels=c("alive","dead","missed"))
>>
>> Duhhh.
>>
>> cheers,
>>
>> Rolf Turner
>
> Maybe you would like to look at the structure.
>
> str(y)
> Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...
>
> or
>
> dput(y)
> structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
> 1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
> 1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
> 2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
> 2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
> 3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
> 2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
> ), class = "factor")
> >
>
> Anything else but positive integers?
>

You clearly do not understand factors. RTFM.

cheers,

Rolf Turner

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Daniel Nordlund-4

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
> On Behalf Of Rolf Turner
> Sent: Thursday, August 11, 2011 5:24 PM
> To: Heinz Tuechler
> Cc: Zeki Çatav; [hidden email]; Uwe Ligges
> Subject: Re: [R] value.labels
>
> On 12/08/11 12:53, Heinz Tuechler wrote:
> > At 12.08.2011 11:05 +1200, Rolf Turner wrote:
> >> On 12/08/11 11:34, Heinz Tuechler wrote:
> >>> At 12.08.2011 09:11 +1200, Rolf Turner wrote:
> >>>> On 12/08/11 09:59, Heinz Tuechler wrote:
> >>>>> At 11.08.2011 21:50 +0300, Zeki Çatav wrote:
> >>>>>> Prş, 2011-08-11 tarihinde 19:27 +0200 saatinde, Uwe Ligges yazdı:
> >>>>>> >
> >>>>>> > On 11.08.2011 19:22, David Winsemius wrote:
> >>>>>> > >
> >>>>>> > > On Aug 11, 2011, at 11:42 AM, Uwe Ligges wrote:
> >>>>>> > >
> >>>>>> > >>
> >>>>>> > >>
> >>>>>> > >> On 11.08.2011 16:10, zcatav wrote:
> >>>>>> > >>> Hello R people,
> >>>>>> > >>>
> >>>>>> > >>> I have a "data.frame". Status variable has 3 values. 0-
> >alive,
> >>>>>> > >>> 1->dead and
> >>>>>> > >>> 2->missed..........................
> >>>>>> > .........................................
> >>>>>> > As I understood the question, just how to rename the levels was
> >>>>>> the
> >>>>>> > original question.
> >>>>>> >
> >>>>>> > Uwe
> >>>>>>
> >>>>>> I don't want to rename levels or converting from numeric to
> >>>>>> string. I
> >>>>>> want to add each corresponding levels value, a label, as in SPSS.
> >>>>>> Level 0 labeled with alive,
> >>>>>> level 1 labeled with dead and
> >>>>>> level 2 labeled with missed.
> >>>>>
> >>>>> This is not possible with a factor, because factor levels can only
> >>>>> be positive integers.
> >>>>
> >>>> That is just plain (ridiculously) wrong. RTFM.
> >>>>
> >>>> cheers,
> >>>>
> >>>> Rolf Turner
> >>>
> >>> So, how would you construct a factor with levels 0, 1, 2 and labels
> >>> alive, dead, and missed, as the original post asked for?
> >>>
> >>> Heinz
> >>
> >> As I said, RTFM. But for completeness:
> >>
> >> x <- sample(0:2,100,TRUE)
> >> y <- factor(x,labels=c("alive","dead","missed"))
> >>
> >> Duhhh.
> >>
> >> cheers,
> >>
> >> Rolf Turner
> >
> > Maybe you would like to look at the structure.
> >
> > str(y)
> > Factor w/ 3 levels "alive","dead",..: 3 1 2 2 3 3 2 1 1 1 ...
> >
> > or
> >
> > dput(y)
> > structure(c(3L, 1L, 2L, 2L, 3L, 3L, 2L, 1L, 1L, 1L, 2L, 1L, 3L,
> > 1L, 2L, 3L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 3L, 1L, 2L, 1L, 2L, 1L,
> > 1L, 3L, 1L, 2L, 3L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L,
> > 2L, 1L, 2L, 3L, 3L, 2L, 1L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 1L,
> > 2L, 2L, 1L, 2L, 1L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L,
> > 3L, 1L, 3L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 2L, 2L, 1L, 1L, 1L,
> > 2L, 3L, 3L, 2L, 1L, 2L, 3L), .Label = c("alive", "dead", "missed"
> > ), class = "factor")
> > >
> >
> > Anything else but positive integers?
> >
>
> You clearly do not understand factors. RTFM.
>
> cheers,
>
> Rolf Turner
>

Rolf,

Clearly, someone doesn't understand something, and it may be me.  I understood the OP to be asking if there was a way of adding labels to specific variable values without changing the underlying values (like a format in SAS or apparently "value labels" in SPSS).  To use your example

x <- sample(0:2,100,TRUE)

The OP wanted to "associate" the label "alive" with the value 0, but didn't want the underlying value in x to change.  The construction

y <- factor(x,labels=c("alive","dead","missed"))

creates a factor, y, where the underlying factor value is 1 and the label is "alive" where x had the value of 0.  Without retaining the vector x, or knowing how y was created, one can't get back to the original value of 0.  I am agnostic about whether that is good or bad, but it seems that your approach does not meet the OP's original request.  Am I missing someting?

Dan

Daniel Nordlund
Bothell, WA USA

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

David Winsemius
In reply to this post by Uwe Ligges-3

On Aug 11, 2011, at 10:27 AM, Uwe Ligges wrote:

> On 11.08.2011 19:22, David Winsemius wrote:
>
> Hmm, when you want to add a level without changing the class of the  
> factor object, you will have to add the level at first and then  
> assign the level to the elements of the object. I'd probably rebuild  
> the whole thing in that case.
>

All I wanted to do was construct a "not done" label for the NA's in a  
factor created with cut so they would show up in tabulations. I think  
the answer to my question is to use `addNA`  and then use `levels<-`  
to change the NA level to "not done". I suppose RTFM is one way to  
answer the question and that was how I figured out what I now know.  
Looks like I can use either factor(x, exclude=NULL) or addNA(x.c)

This builds a test factor:

x<-rnorm(100)
is.na(x) <- sample(c(TRUE,FALSE), 100, c(.1,.9) , replace=TRUE)
x.c <- cut(x, seq(-3,3, by=0.5))

# I think these do the same thing:
x.cE <- factor(x, exclude=NULL)
x.cNA <- addNA(x.c)

# Relabel the NA level
levels(x.cNA) <- c(levels(x.c2)[-length(levels(x.c2))], "NotDone")

 > table(x.cNA)
x.cNA
(-3,-2.5] (-2.5,-2] (-2,-1.5] (-1.5,-1] (-1,-0.5]  (-0.5,0]    
(0,0.5]   (0.5,1]   (1,1.5]   (1.5,2]
         0         0         3         5        16        17        
14        14        15         4
   (2,2.5]   (2.5,3]   NotDone
         2         1         9

That seems a bit less baroque than converting to numeric , changing  
NA's to 0 and then adjusting the factor labels, although I still want  
to move the not-done level so it is first.

x.cN <- factor(x.cNA, levels=c("NotDone", c(levels(x.cNA)[-
length(levels(x.cNA))]))
 > table(x.cN)
x.cN
   NotDone (-3,-2.5] (-2.5,-2] (-2,-1.5] (-1.5,-1] (-1,-0.5]  
(-0.5,0]   (0,0.5]   (0.5,1]   (1,1.5]
         9         0         0         3         5        16        
17        14        14        15
   (1.5,2]   (2,2.5]   (2.5,3]
         4         2         1

> As I understood the question, just how to rename the levels was the  
> original question.

Yes, that was how I understood it as well. I was asking what I thought  
was a related question.

>
> Uwe
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Jim Lemon
In reply to this post by zcatav
On 08/12/2011 12:10 AM, zcatav wrote:

> Hello R people,
>
> I have a "data.frame". Status variable has 3 values. 0->alive, 1->dead and
> 2->missed
> Status as a factor have correct levels. Levels and labels output as follows;
>
> levels(Adbf$status); labels(Adbf$status)
> [1] "0" "1" "2"
>    [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"
>   [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"
>   [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"
>   [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"
>   [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"
>
> ........................................................................"644"
>
> Can i add value.labels to status variable? If yes how? Can i see these
> value.labels on results or graphics?
>
Hi zcatav,
There is a convenience function in the prettyR package named
"add.value.labels" that does just that. It is there mostly so that
someone with data not converted from SPSS can make them look like data
that has been converted from SPSS. I don't know whether the method used
will work with functions from any other package, though.

Jim

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

zcatav
Hi,
My data.frame as follows;

        a        b        c d
1 58009        2010-11-02 0 NA
2 114761 2011-07-28 1 2008-11-05
3 184440 2011-07-28 1 2009-12-08
4 189372 2011-07-28 0 NA
5 105286 NA     2 NA
6 186717 2011-07-28 0 NA
7 189106 2011-07-28 0 NA
8 127306 2011-07-28 0 NA
9 157342 2011-04-25 0 NA

> library("prettyR")
> add.value.labels(test2$c, "alive","dead","missed")
Error in add.value.labels(test2$c, "alive", "dead", "missed") :
  unused argument(s) ("dead", "missed")

> add.value.labels(test2$c, "alive")
[1] 0 1 1 0 2 0 0 0 0
attr(,"value.labels")
alive  <NA>  <NA>
    0     1     2

This function allows only one label. How can add second and other labels?

Thanks.

--
View this message in context: http://r.789695.n4.nabble.com/value-labels-tp3735947p3738244.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

zcatav
In reply to this post by Jim Lemon
Jim Lemon wrote
On 08/12/2011 12:10 AM, zcatav wrote:
> Hello R people,
>
> I have a "data.frame". Status variable has 3 values. 0->alive, 1->dead and
> 2->missed
> Status as a factor have correct levels. Levels and labels output as follows;
>
> levels(Adbf$status); labels(Adbf$status)
> [1] "0" "1" "2"
>    [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"
>   [11] "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"
>   [21] "21"  "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"
>   [31] "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"
>   [41] "41"  "42"  "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"
>
> ........................................................................"644"
>
> Can i add value.labels to status variable? If yes how? Can i see these
> value.labels on results or graphics?
>
Hi zcatav,
There is a convenience function in the prettyR package named
"add.value.labels" that does just that. It is there mostly so that
someone with data not converted from SPSS can make them look like data
that has been converted from SPSS. I don't know whether the method used
will work with functions from any other package, though.

Jim

______________________________________________
[hidden email] 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.
Hi,
My data.frame as follows;

   a          b                 c d
1 58009   2010-11-02 0 NA
2 114761 2011-07-28 1 2008-11-05
3 184440 2011-07-28 1 2009-12-08
4 189372 2011-07-28 0 NA
5 105286 NA              2 NA
6 186717 2011-07-28 0 NA
7 189106 2011-07-28 0 NA
8 127306 2011-07-28 0 NA
9 157342 2011-04-25 0 NA

> library("prettyR")
> add.value.labels(test2$c, "alive","dead","missed")
Error in add.value.labels(test2$c, "alive", "dead", "missed") :
  unused argument(s) ("dead", "missed")

> add.value.labels(test2$c, "alive")
[1] 0 1 1 0 2 0 0 0 0
attr(,"value.labels")
alive  <NA>  <NA> 
    0     1     2

This function allows only one label. How can add second and other labels?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

Bert Gunter
In reply to this post by Daniel Nordlund-4
Doesn't:

 x <- sample(0:2,100,TRUE)

y <- structure(factor(x,labels=c("alive","dead","missed")), orig.labs=x)

do what you want?

-- Bert


> The OP wanted to "associate" the label "alive" with the value 0, but didn't want the underlying value in x to change.  The construction
>
> y <- factor(x,labels=c("alive","dead","missed"))
>
> creates a factor, y, where the underlying factor value is 1 and the label is "alive" where x had the value of 0.  Without retaining the vector x, or knowing how y was created, one can't get back to the original value of 0.  I am agnostic about whether that is good or bad, but it seems that your approach does not meet the OP's original request.  Am I missing someting?
>
> Dan
>
> Daniel Nordlund
> Bothell, WA USA
>
> ______________________________________________
> [hidden email] 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.
>



--
"Men by nature long to get on to the ultimate truths, and will often
be impatient with elementary studies or fight shy of them. If it were
possible to reach the ultimate truths without the elementary studies
usually prefixed to them, these would not be preparatory studies but
superfluous diversions."

-- Maimonides (1135-1204)

Bert Gunter
Genentech Nonclinical Biostatistics

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: value.labels

zcatav
In reply to this post by zcatav
Jim Lemon wrote
Hi Zeki,

fgh<-read.table("fgh.tab",header=TRUE,sep="\t")
fgh$c<-add.value.labels(fgh$c,c("alive","dead","zombie"))
fgh$c

Jim
Thanks Jim,
This is what i want.

Result as follows;

> test2$c<-add.value.labels(test2$c,c("alive","dead","zombie"))
> test2$c
[1] 0 1 1 0 2 0 0 0 0
attr(,"value.labels")
 alive   dead zombie
     0      1      2
> table(test2$c)

0 1 2
6 2 1
> str(test2)
'data.frame': 9 obs. of  4 variables:
 $ a: int  58009 114761 184440 189372 105286 186717 189106 127306 157342
 $ b: Date, format: "2011-07-28" "2008-11-05" ...
 $ c: atomic  0 1 1 0 2 0 0 0 0
  ..- attr(*, "value.labels")= Named num  0 1 2
  .. ..- attr(*, "names")= chr  "alive" "dead" "zombie"
 $ d: Date, format: NA "2008-11-05" ...