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
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@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@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]]
Something like this?
my_data=read.table("clipboard", header=TRUE)
my_data$s_name <- factor(my_data$s_name)
library(plyr)
ddply(my_data, .(s_name), function(x){
x$Im_looking <- x$Depth + as.numeric(x$s_name) / 100
x
})
Best regards,
Thierry
----------------------------------------------------------------------------
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium
Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than
asking him to perform a post-mortem examination: he may be able to say what the
experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure
that a reasonable answer can be extracted from a given body of data.
~ John Tukey
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] Namens Ortiz, John
> Verzonden: maandag 14 maart 2011 15:18
> Aan: r-help at r-project.org
> Onderwerp: [R] increase a value by each group?
>
>
> 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.
>
On Mon, Mar 14, 2011 at 9:59 AM, ONKELINX, Thierry <Thierry.ONKELINX at inbo.be> wrote:> Something like this? > > my_data=read.table("clipboard", header=TRUE) > my_data$s_name <- factor(my_data$s_name) > library(plyr) > ddply(my_data, .(s_name), function(x){ > ? ? ? ?x$Im_looking <- x$Depth + as.numeric(x$s_name) / 100 > ? ? ? ?x > })I think you need factor in there: ddply(my_data, .(s_name), function(x){ ? ? ? ?x$Im_looking <- x$Depth + as.numeric(factor(x$s_name)) / 100 ? ? ? ?x }) or with transform: ddply(my_data, "s_name", transform, Im_looking = Depth + as.numeric(factor(s_name)) / 100) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/