January 21st, 2010
You can specify default settings for MySQL in the file ~/.my.cnf (create it if it doesn’t exist). E.g., you could spare yourself typing your password each time you connect with an entry in that file like this:
[client]
password='mypassword'
This gets loaded in addition to the system configuration file, which for me is at /etc/mysql/my.cnf.
Posted in mysql | No Comments »
January 20th, 2010
Memo to self: I installed RMySQL using
sudo aptitude install r-cran-rmysql
because when I used
install.packages("RMySQL")
it asked my to specify the MySQL libraries and headers and whatnot and don’t know where they are.
Posted in R | No Comments »
January 7th, 2010
When you start using R, it can be confusing that if you assign something to an object you do not get visual feedback:
x <- rep(1:3,5)
You have to then type x to see it:
> x
[1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
You can exploit this fact for doing a quick-and-dirty lottery. Assume you have a file with email addresses, one per line, called "entries.txt". First, read them and assign them to an object:
entries <- readLines("entries.txt")
Next, create an index of numbers of the same length but in random order:
index <- sample(1:length(entries),length(entries))
Note that you don't see it unless you type index. Combine index and emails in a dataframe (also not directly visible):
dat <- data.frame(cbind(index,entries))
Now, go to random.org and draw a number from the index. Type dat to reveal who you drew. This method makes it a bit more "blind" and a bit less likely that you'll cheat.
Posted in Noobs, R | No Comments »
November 9th, 2009
For the record. I got an error running hyperref:
Paragraph ended before \Hy@setref@link was complete
This was due to having a regulare closing parenthesis directly after the curly bracket that closed a \ref, like this: (see section \ref{section-1}). Putting in a space between the closing curly bracket and parenthesis solved the problem: ... section-1} )
Posted in LaTeX | 2 Comments »
November 5th, 2009
I don’t know the first thing about programming, but sometimes you see something and appreciate how elegant it is. This small solution from r-help is a good example. Someone wanted, given a vector c('p','p','t','t','t','p','k','t') to produce NA NA 1 2 3
test <- c('p','p','t','t','t','p','k','t')
v <- cumsum(ind <- test == 't')
v[!ind] <- NA
I didn't know you could assign something to an object and use it at the same time. Very neat. So if you wanted this all at once, you could also do:
v <- ifelse(cumsum(ind <- test=='t')==0,NA,cumsum(ind))
or
ifelse((v <- cumsum(test=='t'))==0,NA,v)
Maybe Dimitris' solution is in fact preferred for R, using indexing instead of if/ else, but I don't know enough about R to know whether that makes a difference.
Posted in R | 1 Comment
»