Re: [R] increase a value by each group?

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Mon, 14 Mar 2011 11:43:42 -0300

Try this:

my_data$tave <- sprintf("%s.%02d", my_data$Depth, do.call(c, tapply(my_data$s_name, my_data$Depth, factor)))

On Mon, Mar 14, 2011 at 11:18 AM, Ortiz, John <OrtizJ_at_si.edu> wrote:

>
> Hi everybody.
>
> I'm looking for the way to increase the depth value in 0.01 for each index
> group.
> Easier to explain with this example:
>
>
> >my_data=read.table("clipboard", header=TRUE)
>
> Depth s_name index
> 3852 Site_1 144
> 3852 Site_1 144
> 3852 Site_1 144
> 3852 site_A 145
> 3852 site_A 145
> 3852 site_A 145
> 3852 site_A 145
> 3852 site_B 147
> 3852 site_B 147
> 3852 site_B 147
> 3852 site_B 147
> 54962 site_C 27
> 54962 site_C 27
> 54962 Site_D 217
> 54962 Site_D 217
> 54962 Site_D 217
> 54962 Site_D 217
>
> I'm looking for something like that (four column)
>
> Depth s_name index Im_looking
> 3852 Site_1 144 3852.01
> 3852 Site_1 144 3852.01
> 3852 Site_1 144 3852.01
> 3852 site_A 145 3852.02
> 3852 site_A 145 3852.02
> 3852 site_A 145 3852.02
> 3852 site_A 145 3852.02
> 3852 site_B 147 3852.03
> 3852 site_B 147 3852.03
> 3852 site_B 147 3852.03
> 3852 site_B 147 3852.03
> 54962 site_C 27 54962.01
> 54962 site_C 27 54962.01
> 54962 Site_D 217 54962.02
> 54962 Site_D 217 54962.02
> 54962 Site_D 217 54962.02
> 54962 Site_D 217 54962.02
>
>
> Currently I found the way to increase the depth but not like I need,
>
> tave = my_data$Depth + (ave(my_data$Depth, my_data$index,
> FUN=seq_along))/100
>
> Depth s_name index test
> 3852 Site_1 144 3852.01
> 3852 Site_1 144 3852.02
> 3852 Site_1 144 3852.03
> 3852 site_A 145 3852.01
> 3852 site_A 145 3852.02
> 3852 site_A 145 3852.03
> 3852 site_A 145 3852.04
> 3852 site_B 147 3852.01
> 3852 site_B 147 3852.02
> 3852 site_B 147 3852.03
> 3852 site_B 147 3852.04
> 54962 site_C 27 54962.01
> 54962 site_C 27 54962.02
> 54962 Site_D 217 54962.01
> 54962 Site_D 217 54962.02
> 54962 Site_D 217 54962.03
> 54962 Site_D 217 54962.04
>
>
> I'm looking to increase all index group, not just each element.
>
> Thanks in advance,
>
> John Ortiz
>
> ______________________________________________
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[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.

Received on Mon 14 Mar 2011 - 14:48:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Mar 2011 - 14:50:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive