[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    Re: [R] function ave() with seq_along returning char sequence instead of numeric
From:       Jeff Newmiller <jdnewmil () dcn ! davis ! ca ! us>
Date:       2016-10-31 23:34:10
Message-ID: 95806726-F808-43B1-9AC7-5A8C59AAAF6F () dcn ! davis ! ca ! us
[Download RAW message or body]

The help page describes the first argument x as a numeric... it is not designed to accept character, so the fact that you get anything even close to right is just a bonus.

As the doctor says, "if it hurts, don't do that".

ave( rep( 1, length( v ), v, FUN=seq_along )
-- 
Sent from my phone. Please excuse my brevity.

On October 31, 2016 3:29:01 PM PDT, "Nordlund, Dan (DSHS/RDA)" <NordlDJ@dshs.wa.gov> wrote:
>Given  the following R statements
>
>v <-  c('a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'c', 'c')
>ave(v, list(v), FUN=seq_along)
> [1] "1" "2" "3" "1" "2" "3" "1" "2" "3" "4" 
>
>I was expecting to get a numeric vector back.  I apparently have missed
>something in the documentation.  If vector v is character, then the
>numeric sequence is converted to character before returning.  I can
>work around by doing something like
>
>ave(seq_along(v), list(v), FUN=seq_along)
> [1] 1 2 3 1 2 3 1 2 3 4 
>
>Is the work around the best way to go, or have I missed an option in
>the documentation?
>
>
>Thanks,
>
>Dan
>
>Daniel Nordlund, PhD
>Research and Data Analysis Division
>Services & Enterprise Support Administration
>Washington State Department of Social and Health Services
>
>______________________________________________
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic