[R] Find value in vector (or matrix)
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Thu Nov 20 13:50:10 CET 2003
Pascal A. Niklaus wrote:
> y <- c("a","b","c")
> if("a" in y)
> {
> # "a" is not in y
> }
You are 98% of the way there. The missing two percent is this:
if("a" %in% y) {
...
}
you could also use the 'any' function:
if(any(y=="a")){
...
}
> Also, is there a way to generate character sequences similar to numeric
> sequences, e.g. something like "A":"J" ? I remember having seen a
> command doing this somewhere, but can't find it anymore
R defines two vectors, "letters" and "LETTERS" which have the 26 lower
and upper-case letters of the English alphabet. Subset from them to get
what you want.
Baz
More information about the R-help
mailing list