Thanks, your solution using ave() works perfectly.
/johannes
-Ursprüngliche Nachricht-
Von: Bert Gunter
An: Johannes Radinger
Cc: R help
Gesendet: Mittwoch, 26. März 2014 16:45:43 GMT+00:00
Betreff: Re: [R] dataframe calculations based on certain values of a column
I believe this
dplyr's group_by and mutate can create those columns for you:
var1 <- c("a","b","c","a","b","c","a","b","c")
var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z")
var3 <- c(1,2,2,5,2,6,7,4,4)
df <- data.frame(var1,var2,var3)
dt <- tbl_df(df)
dt %.%
group_by(var2) %.%
mutate(
div = var3[var1 =
On 26-03-2014, at 17:09, Johannes Radinger wrote:
> Hi,
>
> I have data in a dataframe in following structure
> var1 <- c("a","b","c","a","b","c","a","b","c")
> var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z")
> var3 <- c(1,2,2,5,2,6,7,4,4)
> df <- data.frame(var1,var2,var3)
>
> Now I'd like to
I believe this will generalize. But check carefully!
Using your example (Excellent!), use ave():
with(df,ave(seq_along(var1),var2,FUN=function(i)
var3[i]/var3[i][var1[i]=="c"]))
[1] 0.500 1.000 1.000 0.833 0.333 1.000 1.750
[8] 1.000 1.000
This is kind of a l
Hi,
I have data in a dataframe in following structure
var1 <- c("a","b","c","a","b","c","a","b","c")
var2 <- c("X","X","X","Y","Y","Y","Z","Z","Z")
var3 <- c(1,2,2,5,2,6,7,4,4)
df <- data.frame(var1,var2,var3)
Now I'd like to calculate relative values of var3. This values
should be relative to th
t; not work, I do not yet grasp the coding, I am still a novice.
> > Perhaps you or someone else could rerun your code on my original
> > dataframe and see why it did not yield the correct results.
> >
> > Thank you,
> >
> > Mike
> >
> > -Original
try this:
# add 'date' to separate the data
SCHEDULE2 <- within(SCHEDULE2, {
date <- paste(YEAR, '-', MM, '-', DD, sep='')
ARRIVE <- as.POSIXct(paste(date, ARRIVE))
DEPART <- as.POSIXct(paste(date, DEPART))
})
# process each day
result <- lapply(split(SCHEDULE2, SCHEDULE2$date), functi
Thank you,
Mike
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Erich Neuwirth
Sent: Friday, March 19, 2010 1:33 PM
To: r-help@r-project.org
Subject: Re: [R] Dataframe calculations
Sorry,
Oddly I got the use of odds and evens the wrong way
g] On
> Behalf Of Erich Neuwirth
> Sent: Friday, March 19, 2010 11:38 AM
> To: r-help@r-project.org
> Subject: Re: [R] Dataframe calculations
>
> with the following code
>
> newvars()$ARRIVALS and newvars()$DEPARTURES
> will give you the new variables you need.
>
>
t.org] On
Behalf Of Erich Neuwirth
Sent: Friday, March 19, 2010 11:38 AM
To: r-help@r-project.org
Subject: Re: [R] Dataframe calculations
with the following code
newvars()$ARRIVALS and newvars()$DEPARTURES
will give you the new variables you need.
-=-=-=
addDelays <- function(arriveTime,wait
with the following code
newvars()$ARRIVALS and newvars()$DEPARTURES
will give you the new variables you need.
-=-=-=
addDelays <- function(arriveTime,waitVec,travelVec){
start<-as.POSIXct(arriveTime,format="%H:%M:%S")
delays<-as.vector(t(cbind(waitVec,travelVec)))
newtimes<-format(start+
Hi everyone,
My question will probably seem simple to most of you, but I
have spent many hours trying to solve it. I need to perform
a series of sequential calculations on my dataframe that move
across rows and down columns, and then repeat themselves at
each unique 'MM' by 'DD' grouping. Specific
12 matches
Mail list logo