Spent the day on the coffee shop patio fielding OLPC questions - from "Wow, that's cool, what is it?" to "Where can i get one?" I demonstratively poured some tea on the keyboard at one point for waterproof emphasis to "coooool"s. Good times.
Installed R on the green machine (which is now runing
happy-fun-times modified ubuntu.
Spent time working out of Venables and Ripley's "S Programming" book - trying to keep some finals week brain momentum going...
Plunking example code into the green machine. I kept the screen backlight off, just using sunlight and low battery while the sun was up. When i took a break from coding, i could hit the power button to put it to sleep.
So, i worked through some recursion examples, in the meantime discovering my own knowledge-gaps in indexing ( this[-index] is the compliment of this[index] for a numeric index vector, whereas this[!index] is the compliment for a logical index vector) and list packing.
Also, found a test example of "=" not the same as "<-"
a=1:10
> index1 = a>2 ; any(index2<-(a>2)) ; identical(index1, index2)
[1] TRUE
[1] TRUE
> index1 = a>5 ; any(index2=(a>5)) ; identical(index1, index2)
[1] TRUE
[1] FALSE
### index2 assignment isn't made... why?!
I find recursion confusing; debugging recursive functions is especially so! The fruits of my labor are here, with examples of all of the above...
mk.recur = function(a,lim=5, fac=2){
## takes a numeric vector, returns a list of numeric vectors
## with elements greater than lim, multiplied by fac recursively
if(any(index<-a>lim)) {ret=list(a[index])}
if(length(a[!index])==0) {return(ret)}
ret=append(ret, Recall(fac*a[!index], lim, fac))
return(ret)
}
No comments:
Post a Comment