I am confused by the following difference in the behavior of R and S. Any clarification would be greatly appreciated. Jan Erik Backlund Dow AgroSciences, LLC. jebacklund at dow.com R : Copyright 2003, The R Development Core Team Version 1.8.0 (2003-10-08)> swFertility Agriculture Examination Education Catholic Courtelary 80.2 17.0 15 12 9.96 Delemont 83.1 45.1 6 9 84.84 Franches-Mnt 92.5 39.7 5 5 93.40 Moutier 85.8 36.5 12 7 33.77 Neuveville 76.9 43.5 17 15 5.16> sw[2,1][1] 83.1> sw[[2,1]][1] 17>and the corresponding behaviour in S S-PLUS : Copyright (c) 1988, 2001 Insightful Corp. S : Copyright Lucent Technologies, Inc. Professional Edition Version 6.0.3 Release 2 for Microsoft Windows : 2001> swFertility Agriculture Examination Education Catholic Courtelary 80.2 17.0 15 12 9.96 Delemont 83.1 45.1 6 9 84.84 Franches-Mnt 92.5 39.7 5 5 93.40 Moutier 85.8 36.5 12 7 33.77 Neuveville 76.9 43.5 17 15 5.16> sw[2,1][1] 83.1> sw[[2,1]][1] 83.1
On Fri, 17 Oct 2003, Backlund, Jan Erik (JE) wrote:> I am confused by the following difference in the behavior of R and S. Any > clarification would be greatly appreciated.sw[[2,1]] in R is short for sw[[2]][[1]], which in the case of a data frame is sw[1,2], as your example shows. -thomas> Jan Erik Backlund > Dow AgroSciences, LLC. > jebacklund at dow.com > > > R : Copyright 2003, The R Development Core Team > Version 1.8.0 (2003-10-08) > > sw > Fertility Agriculture Examination Education Catholic > Courtelary 80.2 17.0 15 12 9.96 > Delemont 83.1 45.1 6 9 84.84 > Franches-Mnt 92.5 39.7 5 5 93.40 > Moutier 85.8 36.5 12 7 33.77 > Neuveville 76.9 43.5 17 15 5.16 > > sw[2,1] > [1] 83.1 > > sw[[2,1]] > [1] 17 > > > > and the corresponding behaviour in S > S-PLUS : Copyright (c) 1988, 2001 Insightful Corp. > S : Copyright Lucent Technologies, Inc. > Professional Edition Version 6.0.3 Release 2 for Microsoft Windows : 2001 > > sw > Fertility Agriculture Examination Education Catholic > Courtelary 80.2 17.0 15 12 9.96 > Delemont 83.1 45.1 6 9 84.84 > Franches-Mnt 92.5 39.7 5 5 93.40 > Moutier 85.8 36.5 12 7 33.77 > Neuveville 76.9 43.5 17 15 5.16 > > sw[2,1] > [1] 83.1 > > sw[[2,1]] > [1] 83.1 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
See ?[[ "[[" operates recursively, so sw[[2,1]] is the same as sw[[2]][[1]] Giovanni> Date: Fri, 17 Oct 2003 12:30:07 -0400 > From: "Backlund, Jan Erik (JE)" <jebacklund at dow.com> > Sender: r-help-bounces at stat.math.ethz.ch > Cc: > Precedence: list > > I am confused by the following difference in the behavior of R and S. Any > clarification would be greatly appreciated. > Jan Erik Backlund > Dow AgroSciences, LLC. > jebacklund at dow.com > > > R : Copyright 2003, The R Development Core Team > Version 1.8.0 (2003-10-08) > > sw > Fertility Agriculture Examination Education Catholic > Courtelary 80.2 17.0 15 12 9.96 > Delemont 83.1 45.1 6 9 84.84 > Franches-Mnt 92.5 39.7 5 5 93.40 > Moutier 85.8 36.5 12 7 33.77 > Neuveville 76.9 43.5 17 15 5.16 > > sw[2,1] > [1] 83.1 > > sw[[2,1]] > [1] 17 > > > > and the corresponding behaviour in S > S-PLUS : Copyright (c) 1988, 2001 Insightful Corp. > S : Copyright Lucent Technologies, Inc. > Professional Edition Version 6.0.3 Release 2 for Microsoft Windows : 2001 > > sw > Fertility Agriculture Examination Education Catholic > Courtelary 80.2 17.0 15 12 9.96 > Delemont 83.1 45.1 6 9 84.84 > Franches-Mnt 92.5 39.7 5 5 93.40 > Moutier 85.8 36.5 12 7 33.77 > Neuveville 76.9 43.5 17 15 5.16 > > sw[2,1] > [1] 83.1 > > sw[[2,1]] > [1] 83.1 > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > > >-- __________________________________________________ [ ] [ Giovanni Petris GPetris at uark.edu ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__________________________________________________]