Thank you all!
n
On Mon, Sep 21, 2015 at 10:00 PM, Bert Gunter
wrote:
> No.
>
>
> On Mon, Sep 21, 2015 at 10:58 AM, John McKown
> wrote:
> > On Mon, Sep 21, 2015 at 9:52 AM, Nico Gutierrez <
> nico.gutierr...@gmail.com>
> > wrote:
> >
> >> Hi All,
> >>
> >> I need to do the following operation
And the action is?
John Kane
Kingston ON Canada
> -Original Message-
> From: nico.gutierr...@gmail.com
> Sent: Mon, 21 Sep 2015 16:48:45 +0200
> To: r-help@r-project.org
> Subject: [R] extract from data.frame (indexing)
>
> Hi All,
>
> I need to
better ( if year is an vector of more than 1 element):
df[ df$Year %in% outer(as.numeric( as.character( year)), -1:1, FUN='+'), ]
Year Amount
2 2002120
3 2003175
4 2004160
On Mon, Sep 21, 2015 at 10:49:34PM +0200, Frank Schwidom wrote:
>
> year <- df$Year[ which.max( df$Amount)]
year <- df$Year[ which.max( df$Amount)]
df[ df$Year %in% (as.numeric( as.character( year)) + -1:1), ]
Year Amount
2 2002120
3 2003175
4 2004160
On Mon, Sep 21, 2015 at 04:52:46PM +0200, Nico Gutierrez wrote:
> Hi All,
>
> I need to do the following operation from data.frame:
>
>
No.
On Mon, Sep 21, 2015 at 10:58 AM, John McKown
wrote:
> On Mon, Sep 21, 2015 at 9:52 AM, Nico Gutierrez
> wrote:
>
>> Hi All,
>>
>> I need to do the following operation from data.frame:
>>
>> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
>> "2007"), Amount = c(150
Note the following problems:
1. " max_row <- (1:nrow(df))[which.max(df$Amount)]"
This is a bit silly.
max_row <- which.max(df$Amount)
will do. See ?which.max
2. What happens if the max is the first or last row? e.g.
> dat <- data.frame(a=runif(5),b=1:5)
> max_row<- which.max(dat$b)
> mean(d
On Mon, Sep 21, 2015 at 9:52 AM, Nico Gutierrez
wrote:
> Hi All,
>
> I need to do the following operation from data.frame:
>
> df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
> "2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
> df[which.max(df$Amount),] #to extra
Nico,
I expect there are many better ways to do this, but this does work:
max_row <- (1:nrow(df))[which.max(df$Amount)]
mean(df$Amount[max_row + c(-1, 0, 1)])
> max_row <- (1:nrow(df))[which.max(df$Amount)]
> mean(df$Amount[max_row + c(-1, 0, 1)])
[1] 151.6667
R. Mark Sharp, Ph.D.
Director of P
Hi All,
I need to do the following operation from data.frame:
df <- data.frame(Year = c("2001", "2002", "2003", "2004", "2005", "2006",
"2007"), Amount = c(150, 120, 175, 160, 120, 105, 135))
df[which.max(df$Amount),] #to extract row with max Amount.
Now I need to do 3 years average around the
Hi All,
I need to do the following operation:
Year Amount Amount.1
1 2001150 150
2 2002120 120
3 2003175 175
4 2004160 160
5 2005120 120
6 2006105 105
7 2007135 135
[[alternative HTML version deleted]]
___
10 matches
Mail list logo