# R/S difference (data frames)

Andreas Weingessel Andreas.Weingessel@ci.tuwien.ac.at
Wed, 7 Jan 1998 11:54:25 +0100

```In R, it is not possible to use binary operations, like -, on the
lines of a data frame, even if all columns contain numeric values. In
Splus this is possible:

R> a<-data.frame(int1=3D1:3,int2=3D4:6)
R> a[1,]-a[2,]
Error in a[1, ] - a[2, ] : non-numeric argument to binary operator

but

S>  a<-data.frame(int1=3D1:3,int2=3D4:6)
S> a[1,]-a[2,]
int1 int2=20
1   -1   -1

If not all columns contain numeric values, both R and S give an error:

R> b<-data.frame(int1=3D1:3,int2=3D4:6,char=3Dc("a","b","c"))
R> b[1,]-b[2,]
Error in b[1, ] - b[2, ] : non-numeric argument to binary operator

S> b<-data.frame(int1=3D1:3,int2=3D4:6,char=3Dc("a","b","c"))
S> b[1,]-b[2,]
Error in Ops.factor(e1, e2): "-" not meaningful for factors
Dumped

but the following is again different:

R> b<-data.frame(int1=3D1:3,int2=3D4:6,char=3Dc("a","b","c"))
R> b[1,1:2]-b[2,1:2]
Error in b[1, 1:2] - b[2, 1:2] : non-numeric argument to binary operator

S> b<-data.frame(int1=3D1:3,int2=3D4:6,char=3Dc("a","b","c"))
> b[1,1:2]-b[2,1:2]
int1 int2=20
1   -1   -1

************************************************************************
*                          Andreas Weingessel                          *
************************************************************************
* Institut f=FCr Statistik      *                Tel: (+43 1) 58801 4541 =
*
* Technische Universit=E4t Wien *                Fax: (+43 1)  504 14 98 =
*
* Wiedner Hauptstr. 8-10/1071 *     Andreas.Weingessel@ci.tuwien.ac.at *
* A-1040 Wien, Austria        * http://www.ci.tuwien.ac.at/~weingessel *
************************************************************************

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```