Re: [R] Vector docs

2010-05-30 Thread i...@whywouldwe.com
Thanks for this, and all the other responses - I have a better 
understanding now.




David Winsemius wrote:


On May 30, 2010, at 1:43 AM, i...@whywouldwe.com wrote:


Hi

The docs for R are very practical, which is quite refreshing compared 
to other languages, however I can't find any details about all the 
things I can do with a vector. I'm expecting methods like 
vector.contains('foo') and vector.remove('foo'), maybe those methods 
don't exist but I'd love to find a page that details the ones that do.


Since vectors may contain named elements, your request is ambiguous. I 
cannot tell whether "foo" is a name or a value. It's also ambiguous 
because it's not clear what vector.contains() is supposed to return. 
If you read the introductory material, you should find that the 
function "[" is fairly fundamental to R operations.


?"["
?which
?grep

> x <- c(foo=3,bar=4)
> x
foo bar
  3   4
> x["foo"]
foo
  3
> x[-"foo"]
Error in -"foo" : invalid argument to unary operator
# the negation operation on indices only works with numeric arguments
# grep and which provide numeric resutls that can be used for "removal".
> x[grep("foo", names(x))]
foo
  3
> x[-grep("foo", names(x))]
bar
  4
> x[which(names(x)=="foo")]
foo
  3

Minus operations on numeric indices perform removal, at least to the 
extent of what is returned, but indexing does not do destructive 
removal unless accompanied by "<-" . In fact "[<-" is a function in 
its own right.




I'd also like to find some docs about foreach loops (unless there's a 
better way to iterate through a vector), I've only found mailing list 
posts.


Indexed solution are preferred, so see above, but if you want to find 
the help page for the "for" function


?"Control"





--

David Winsemius, MD
West Hartford, CT




__
R-help@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.


Re: [R] Vector docs

2010-05-30 Thread David Winsemius


On May 30, 2010, at 1:43 AM, i...@whywouldwe.com wrote:


Hi

The docs for R are very practical, which is quite refreshing  
compared to other languages, however I can't find any details about  
all the things I can do with a vector. I'm expecting methods like  
vector.contains('foo') and vector.remove('foo'), maybe those methods  
don't exist but I'd love to find a page that details the ones that do.


Since vectors may contain named elements, your request is ambiguous. I  
cannot tell whether "foo" is a name or a value. It's also ambiguous  
because it's not clear what vector.contains() is supposed to return.  
If you read the introductory material, you should find that the  
function "[" is fairly fundamental to R operations.


?"["
?which
?grep

> x <- c(foo=3,bar=4)
> x
foo bar
  3   4
> x["foo"]
foo
  3
> x[-"foo"]
Error in -"foo" : invalid argument to unary operator
# the negation operation on indices only works with numeric arguments
# grep and which provide numeric resutls that can be used for "removal".
> x[grep("foo", names(x))]
foo
  3
> x[-grep("foo", names(x))]
bar
  4
> x[which(names(x)=="foo")]
foo
  3

Minus operations on numeric indices perform removal, at least to the  
extent of what is returned, but indexing does not do destructive  
removal unless accompanied by "<-" . In fact "[<-" is a function in  
its own right.




I'd also like to find some docs about foreach loops (unless there's  
a better way to iterate through a vector), I've only found mailing  
list posts.


Indexed solution are preferred, so see above, but if you want to find  
the help page for the "for" function


?"Control"





--

David Winsemius, MD
West Hartford, CT

__
R-help@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.


Re: [R] Vector docs

2010-05-30 Thread Duncan Murdoch

i...@whywouldwe.com wrote:

Hi

The docs for R are very practical, which is quite refreshing compared to 
other languages, however I can't find any details about all the things I 
can do with a vector. I'm expecting methods like vector.contains('foo') 
and vector.remove('foo'), maybe those methods don't exist but I'd love 
to find a page that details the ones that do.


I'd also like to find some docs about foreach loops (unless there's a 
better way to iterate through a vector), I've only found mailing list posts.


  


There may be such a page somewhere, but it is probably incomplete.  The 
object model in R has methods owned by generics, not by classes.  So 
even if someone wrote a list of all methods that worked on vectors, 
someone else could add a new one without modifying the vector class.


You can ask R what methods are currently visible, e.g.

library(methods)
showMethods(classes="vector")

but it won't show methods in unattached packages.

Duncan Murdoch

__
R-help@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.


[R] Vector docs

2010-05-29 Thread i...@whywouldwe.com

Hi

The docs for R are very practical, which is quite refreshing compared to 
other languages, however I can't find any details about all the things I 
can do with a vector. I'm expecting methods like vector.contains('foo') 
and vector.remove('foo'), maybe those methods don't exist but I'd love 
to find a page that details the ones that do.


I'd also like to find some docs about foreach loops (unless there's a 
better way to iterate through a vector), I've only found mailing list posts.


Thanks

__
R-help@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.