Re: [R] Strange result from single [] extract operator

2013-09-29 Thread Patrick Burns

See Circle 8.1.3 of 'The R Inferno'.

http://www.burns-stat.com/documents/books/the-r-inferno/

Pat

On 28/09/2013 16:18, rafae...@poczta.fm wrote:

Hi All,

I am using Rx64 3.0.1 on Windows 7 x64, and wanted to get two last rows from 
dataset. First, I tried
  library(datasets)

data-airquality
data[nrow(data)-1:nrow(data),]


and received 152 rows sorted desc. Could you explain why it worked this way? I 
changed the extract line to:
data[(nrow(data)-1):nrow(data),]

and then I received what I wanted but still am curious about the performance of 
my previous code.

Yours faithfully,
Rafał

__
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.



--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @burnsstat @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of:
 'Impatient R'
 'The R Inferno'
 'Tao Te Programming')

__
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.


Re: [R] Strange result from single [] extract operator

2013-09-29 Thread Rafał Wojdan
Dear All,

thank you for all answers. First answer helped me understand the
performance of code better, second showed me how to solve the problem
easier and third provided me with interesting pdf to learn.

I am very grateful for your help.

Best regards,
Rafa³



2013/9/29 Patrick Burns pbu...@pburns.seanet.com

 See Circle 8.1.3 of 'The R Inferno'.

 http://www.burns-stat.com/**documents/books/the-r-inferno/http://www.burns-stat.com/documents/books/the-r-inferno/

 Pat


 On 28/09/2013 16:18, rafae...@poczta.fm wrote:

 Hi All,

 I am using Rx64 3.0.1 on Windows 7 x64, and wanted to get two last rows
 from dataset. First, I tried
   library(datasets)

 data-airquality
 data[nrow(data)-1:nrow(data),]


 and received 152 rows sorted desc. Could you explain why it worked this
 way? I changed the extract line to:
 data[(nrow(data)-1):nrow(data)**,]

 and then I received what I wanted but still am curious about the
 performance of my previous code.

 Yours faithfully,
 Rafa³

 __**
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/**
 posting-guide.html http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 --
 Patrick Burns
 pbu...@pburns.seanet.com
 twitter: @burnsstat @portfolioprobe
 http://www.portfolioprobe.com/**blog http://www.portfolioprobe.com/blog
 http://www.burns-stat.com
 (home of:
  'Impatient R'
  'The R Inferno'
  'Tao Te Programming')


[[alternative HTML version deleted]]

__
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.


[R] Strange result from single [] extract operator

2013-09-28 Thread rafael . 7
Hi All,

I am using Rx64 3.0.1 on Windows 7 x64, and wanted to get two last rows from 
dataset. First, I tried
 library(datasets)
 data-airquality
 data[nrow(data)-1:nrow(data),]

and received 152 rows sorted desc. Could you explain why it worked this way? I 
changed the extract line to:
data[(nrow(data)-1):nrow(data),]

and then I received what I wanted but still am curious about the performance of 
my previous code.

Yours faithfully,
Rafał 

__
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.


Re: [R] Strange result from single [] extract operator

2013-09-28 Thread William Dunlap
 First, I tried
  library(datasets)
  data-airquality
  data[nrow(data)-1:nrow(data),]
 
 and received 152 rows sorted desc. Could you explain why it worked this way? 
 I changed
 the extract line to:
 data[(nrow(data)-1):nrow(data),]
 
 and then I received what I wanted but still am curious about the performance 
 of my
 previous code.

Back up a little and compare
nrow(data)-1:nrow(data)
to
(nrow(data)-1):nrow(data)
or compare
   3-1:3
to
   (3-1):3

Then look at the help file for Syntax.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of rafae...@poczta.fm
 Sent: Saturday, September 28, 2013 8:18 AM
 To: r-help@r-project.org
 Subject: [R] Strange result from single [] extract operator
 
 Hi All,
 
 I am using Rx64 3.0.1 on Windows 7 x64, and wanted to get two last rows from 
 dataset.
 First, I tried
  library(datasets)
  data-airquality
  data[nrow(data)-1:nrow(data),]
 
 and received 152 rows sorted desc. Could you explain why it worked this way? 
 I changed
 the extract line to:
 data[(nrow(data)-1):nrow(data),]
 
 and then I received what I wanted but still am curious about the performance 
 of my
 previous code.
 
 Yours faithfully,
 Rafał
 
 __
 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.
__
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.