r


18
Mar 10

R: Count unique items in a vector

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

Useful R link

Questions at stackoverflow about R:


17
Mar 10

R: “while” loops

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

R tip iterating over list

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

for (name in names(myList)) {
    print(name)
print(myList[[name]])
}

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