This is post handling synchronization of Java threads is made as the follow-up of Creating threads in Java.
There we had the situation that our threads evens and odds weren’t running smoothly. A solution for that is adding a time-out after the thread’s main task. We’ll do this by calling the static method sleep(int millis) of class Thread which will cause the thread it’s been called by to sleep for millis milliseconds. As this method throws an exception we also need to catch it and preferably handle it.
Continue reading “Synchronizing threads in Java”
Synchronizing threads in Java
Creating threads in Java
Concurrency is a really great concept – multi-tasking and event handling are just two of the many spots it finds application and are amongst those things that makes computers stand nowadays where they are. Almost every operating system supports processes – various running programs, which to a certain extent are separated from each other.
Continue reading “Creating threads in Java”
Plot symbols in R
There’s a rich variety of plotting symbols for all basic plotting functions from the graphics package in R. You need to set the pch parameter in the call of the plotting routine. It’s an integer set by default to one and usually having a value between 0 and 25.
- 0:18 – S compatible plot symbols
- 19:25 – further R plot symbols
- 26:31 – unused – a value from this range will be ignored
- 32:127 – ASCII characters
For more detailed information please check the manual for the points function.
R: Extract matrix rows by matching values in different columns
Recently I needed a SQL-”select * where”-query-like way to extract rows of a matrix by matching values of specific columns, something like:
SELECT * FROM `tablename` WHERE `column_a`=’x’ AND `col_b`=’y’
I already knew how to use the extract function (using the []) to get a part of matrix or vector by matching single logical condition on all matrix elements. And that in two ways – more about selecting elements and finding indexes of elements see the post about how to select elements or find their index in a vector or a matrix in R.
Continue reading “R: Extract matrix rows by matching values in different columns”
R: Select specific elements or find their index in a vector or a matrix
As the title suggests in this post I’d like to explain something very basic and very essential. In R (as in other languages) you may do things in different ways. Sometimes it doesn’t matter which way you choose, but sometimes it really does. Once you’d need to extract elements from vector or matrix, another time you’d like to know the index of a specific element.
Say we have the following matrix:
x <- matrix( c(.007, 0.012, .022, 0.000, .005, 0.112, .027, 1.000, .037, .001, .061, .055), nrow=4, ncol=3, byrow=TRUE )
Continue reading "R: Select specific elements or find their index in a vector or a matrix"






