[R] Give me all operator

Ivan Calandra ivan.calandra at uni-hamburg.de
Wed Nov 17 14:44:17 CET 2010


Hi Alex,

Is that what you're looking for:
 > df <- data.frame(a=LETTERS[1:5], b=rnorm(5))
 > df
   a          b
1 A -0.2401323
2 B -0.9414998
3 C  0.4289836
4 D  1.9802749
5 E -0.6993612
 > df[3,2]
[1] 0.4289836
 > df[3,]
   a         b
3 C 0.4289836
 > df[,2]
[1] -0.2401323 -0.9414998  0.4289836  1.9802749 -0.6993612
 > df[,2, drop=FALSE]
            b
1 -0.2401323
2 -0.9414998
3  0.4289836
4  1.9802749
5 -0.6993612

See ?"[" for help. In short, in R you use "[", not brackets as in matlab 
(from your example, I've never used it). You don't need the ":", you 
just don't write anything in R.

Ivan

Le 11/17/2010 14:34, Alaios a écrit :
> Hello is there in R any operator that give you all the data of a matrix
> for example in matlab
>
> x(2,3) returns the 2ndth row and 3rdth column
> x(2,:) returns all the columns of the 2nd row.
>
> In R now I would like to print all the
>
>   CRagent[[i]][2]
>
>
>   CRagent[[:]][2] doesnot work of course. Other option is to make a loop with an index i that spans from 1:last element of CRagent[[]] but this is not that optimal.
>
> I would like to thank you in aavance for your help
> Best Regards
> Alex
>
>
>
>
> 	[[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at 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.

-- 
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calandra at uni-hamburg.de

**********
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php



More information about the R-help mailing list