Had to look this one up, so here it is:

length(unique(x))

Counts the number of distinct items in a vector in R.

In Monte Carlo We Trust

18

Mar 10

Had to look this one up, so here it is:

length(unique(x))

Counts the number of distinct items in a vector in R.

17

Mar 10

R has regular while loops:

while (condition) {

Note that if you try to get help about while you get an error:

help(while)

Error: unexpected ‘)’ in “help(while)”

16

Mar 10

>

Error in -value : invalid argument to unary operator

The problem was that I had the following code

`fcnName <<-- value`

Check out the extra dash typo, since R gives you no line numbers with the errors it took me a bit to track this down. Note the double << makes the assignment global in scope.

16

Mar 10

To iterate over a list by key, value pair, do this:

for (name in names(myList)) { print(name)<br /> print(myList[[name]])<br /> }

Note the double [[]] so you get just the value, not the pair.