[R] Explanation w.r.t. rbind, please!

Uwe Dippel udippel at uniten.edu.my
Fri Jan 29 11:56:56 CET 2010


This is what I tried:

 > num.vec <- c(12.34,56.78,90.12,34.56)
 > names(num.vec)<-c("first","second","third","fourth")
 > num.vec
 first second  third fourth
 12.34  56.78  90.12  34.56
 > seq<-(1:4)                          
 > num.mat<-rbind(num.vec,seq)
 > num.mat                   
        first second third fourth
num.vec 12.34  56.78 90.12  34.56
seq      1.00   2.00  3.00   4.00
 > num.vec [3:4]
 third fourth 
 90.12  34.56

(until here I'm fine)

 > num.mat [seq]
[1] 12.34  1.00 56.78  2.00
 > num.mat [num.vec]
[1] NA NA NA NA   
 > num.vec [seq]
 first second  third fourth
 12.34  56.78  90.12  34.56
 > num.mat [num.vec]        
[1] NA NA NA NA            
 > num.mat [-seq]          
[1] 90.12  3.00 34.56  4.00

(and here I'm lost!)

How could I display a row, instead of always seemingly falling back to 
columns?

Uwe



More information about the R-help mailing list