[R] Equivalents of Matlab's 'find' and 'end'
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.ac.be
Thu Oct 7 16:35:30 CEST 2004
Hi Bryan,
1. which(x==1)
2. X[2:nrow(X),] or X[,2:ncol(X)]
The "An Introduction to R" document is very usdeful for this kind of
things.
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/396887
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Bryan L. Brown" <stonefly at mail.utexas.edu>
To: <R-help at stat.math.ethz.ch>
Sent: Thursday, October 07, 2004 4:10 PM
Subject: [R] Equivalents of Matlab's 'find' and 'end'
> Sorry if these questions have been asked recently--I'm new to this
> list.
>
> I'm primarily a Matlab user who is attempting to learn R and I'm
> searching for possible equivalents of commands that I found very
> handy in Matlab. So that I don't seem ungrateful to those who may
> answer, I HAVE determined ways to carry out these processes in
> 'brute force' sorts of ways in R code, but they lack the elegance
> and simplicity of the Matlab commands. Also, if you know that no
> such commands exist, that bit of knowledge would be helpful to know
> so that I don't continue fruitless searches.
>
> The first is Matlab's 'find' command.
> This is one of the most useful commands in Matab. Basically, if X
> is the vector
>
> X=[3, 2, 1, 1, 2, 3]
>
> the command
>
> 'find(X==1)'
>
> would return the vector [3, 4] which would indicate that the vector
> X had the value of 1 at the 3 and 4 positions. This was an
> extremely useful command for subsetting in Matlab. The closest
> thing I've found in R has been 'match' but match only returns the
> first value as opposed to the position of all matching values.
>
> The second Matlab command that I'd like to find an R equivalent for
> is 'end'. 'end' is just a simple little command that indicates the
> end of a row/column. It is incredibly handy when used to subset
> matrices like
>
> Y = X(2:end)
>
> and produces Y=[2, 1, 1, 2, 3] if the X is the same as in the
> previous example. This cutsie little command was extremely useful
> for composing programs that were flexible and could use input
> matrices of any size without modifying the code. I realize that you
> can accomplish the same by Y <- X[2:length(X)] in R, but this method
> is ungainly, particularly when subsetting matrices rather than
> vectors.
>
> If anyone has advice, I'd be grateful,
>
> Bryan L. Brown
> Integrative Biology
> University of Texas at Austin
> Austin, TX 78712
> 512-965-0678
> stonefly at mail.utexas.edu
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list