Re: [R] data frame row manipulation

2007-08-31 Thread Gabor Grothendieck
Try this:

evaluation$maxVol <- ave(evaluation$vol, evaluation$name, FUN = max)

or using SQL via sqldf like this:

library(sqldf)
sqldf("select * from evaluation join
  (select name, max(vol) from evaluation group by name) using (name)")


On 8/31/07, Calle <[EMAIL PROTECTED]> wrote:
> Hello,
>
> struggling with the very basic needs... :( any help appreciated.
>
> #using the package doBY
> #who drinks how much beer per day and therefor cannot calculate rowise
> maxvals
> evaluation=data.frame(date=c(1,2,3,4,5,6,7,8,9),
> name=c("Michael","Steve","Bob",
> "Michael","Steve","Bob","Michael","Steve","Bob"), vol=c(3,5,4,2,4,5,7,6,7))
> evaluation #
>
> maxval=summaryBy(vol ~ name,data=evaluation,FUN = function(x) { c(ma=max(x))
> } )
> maxval # over all days per person
>
> #function
> getMaxVal=function(x) { maxval$vol.ma[maxval$name==x] }
> getMaxVal("Steve") # testing the function for one name is ok
>
> #we want to add a column, that shows the daily drinkingvolume in relation to
> the persons max-vol.
> evaluation[,"relDrink"]= evaluation$vol/getMaxVal(evaluation$name)
> #
> # this brings the error:
> #
> #Warning message:
> # Korrupter Data Frame: Spalten werden abgeschnitten oder mit NAs
> # aufgefüllt in: format.data.frame(x, digits = digits, na.encode = FALSE)
>
> errortest= evaluation$vol/getMaxVal(evaluation$name)
> errortest
> # this brings:
> # numeric(0)
>
>
> #target was the following:
> #show in each line the daily consumed beer per person and in the next column
>
> #the all time max consumed beer for this person´(or divided by daily vol):
> #
> #  datename vol relDrink
> #11 Michael   37
> #22   Steve   56
> #33 Bob   47
> #44 Michael   27
> #55   Steve   47
> #66 Bob   57
> #77 Michael   77
> #88   Steve   66
> #99 Bob   77
>
> # who can help???
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] data frame row manipulation

2007-08-31 Thread Calle
Hello,

struggling with the very basic needs... :( any help appreciated.

#using the package doBY
#who drinks how much beer per day and therefor cannot calculate rowise
maxvals
evaluation=data.frame(date=c(1,2,3,4,5,6,7,8,9),
name=c("Michael","Steve","Bob",
"Michael","Steve","Bob","Michael","Steve","Bob"), vol=c(3,5,4,2,4,5,7,6,7))
evaluation #

maxval=summaryBy(vol ~ name,data=evaluation,FUN = function(x) { c(ma=max(x))
} )
maxval # over all days per person

#function
getMaxVal=function(x) { maxval$vol.ma[maxval$name==x] }
getMaxVal("Steve") # testing the function for one name is ok

#we want to add a column, that shows the daily drinkingvolume in relation to
the persons max-vol.
evaluation[,"relDrink"]= evaluation$vol/getMaxVal(evaluation$name)
#
# this brings the error:
#
#Warning message:
# Korrupter Data Frame: Spalten werden abgeschnitten oder mit NAs
# aufgefüllt in: format.data.frame(x, digits = digits, na.encode = FALSE)

errortest= evaluation$vol/getMaxVal(evaluation$name)
errortest
# this brings:
# numeric(0)


#target was the following:
#show in each line the daily consumed beer per person and in the next column

#the all time max consumed beer for this person´(or divided by daily vol):
#
#  datename vol relDrink
#11 Michael   37
#22   Steve   56
#33 Bob   47
#44 Michael   27
#55   Steve   47
#66 Bob   57
#77 Michael   77
#88   Steve   66
#99 Bob   77

# who can help???

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch 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.