Dear knowing people,

I have a data frame like this.

exdatframe <- data.frame(Name=c("Ernie","Ernie","Ernie", "CookieMonster","CookieMonster","CookieMonster"),
recordedTime=as.POSIXct(strptime(as.character("01.01.2017","02.01.2011","03.01.2011",
"01.01.2011","02.01.2011","03.01.2011"),"%d.%m.%Y")),
                         week =c(1,2,2,
                                1,2,2),
                         eatencookies=c(1,0.5,0.001,
                                       50,51,200))
exdatframe

#Now I want a new dataframe with only the first row per week (i.e. I want to know how many cookies were eaten at the first recorded day of each week). Something like that:

exdatframe2 <- data.frame(Name=c("Ernie","Ernie", "CookieMonster","CookieMonster"),
                         recordedTime=c("01.01.2017","02.01.2011",
"01.01.2011","02.01.2011"),
                         week =c(1,2,
                                 1,2),
                         eatencookies=c(1,0.5,
                                        50,51))
exdatframe2

# How do I do that? I thought it must be something with tapply or subset - but I just don't get it....

# would be great if someone helps.

# Dagmar

______________________________________________
[email protected] 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.

Reply via email to