[R] Odd behaviour of subset indexing (x:y).

John Sorkin jsorkin at grecc.umaryland.edu
Wed Jan 21 00:01:59 CET 2009


R 2.8.1
windows XP

I don't understand the output from x[iS+1:iE] produced by the code below:

x = c(1,2,3,4,5)
x
 [1] 1 2 3 4 5

 iS=2   #  start position
 iE=4   #  end position

[iS:iE]
[1] 2 3 4

# I don't understand the results of the command below. I would expect to see 3, 4, not 3, 4, 5, NA
x[iS+1:iE]
[1]  3  4  5 NA

Thanks,
John



John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence

University of Maryland School of Medicine
Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524

(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
jsorkin at grecc.umaryland.edu
Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}




More information about the R-help mailing list