Skip to navigation

Use sed to remove the first column in a comma separated file (csv)

August 2nd, 2010

Here’s how:

sed -i 's/[^,]*,//' file.csv

Note the [^,]* bit, which matches everything that is not a comma. Don’t use .*, because this will greedily match commas, too. (Usually, cut is useful for these sort of things, but cut cannot readily replace the file in place.)

How to get Emacs key bindings in Ubuntu

February 16th, 2010

To get the Emacs key bindings (especially, Ctrl-a to go to beginning of line, Ctrl-e to end of line) systemwide, e.g. in Firefox, you use:

gconf-editor

and change the setting desktop → gnome → interface → gtk_key_theme from “Default” to “Emacs”.

How not to ask a question on R-help

February 12th, 2010

One great way to get help with R is by asking a question on the r-help mailing list. More often than not I have actually figured out the answer simply by typing up the question, because that made me think more clearly about what the problem really was. The people on the list are exceedingly helpful. Not all of the posters are. I’ll now start collecting some fun examples of threads which might be called “How not to ask a quesiton on R-help”. Here is the first one. Nice quote from Greg Snow:

If you show us your data/code/output as has been requested, then we may be able to tell which it is. Without that information you are expecting either R or the members of the list to read your mind. I keep making notes to my future self to use the timetravel package (not written yet, that’s why I need my future self to use it) to send a copy of the esp package (also not written yet) back in time to me so I can use it for situations like this. But so far that has not worked (maybe my future self is even more lazy than my present self, or my near future self does something to offend my far future self enough that he is unwilling to do this small favor for my current past self, darn, either way means I should probably do better on the diet/exercise).

R: loops vs apply (vectorization)

February 10th, 2010

A helpful article in by Uwe Ligges and John Fox in R news 2008(1), pp 46-50, about loops vs. apply was just pointed out on R-help. I’ve uploaded it here (pdf).

My first RMySQL session

January 21st, 2010
# 'fai1' is an empty MySQL database for which 'mpromber' has all privileges
mycon <- dbConnect(MySQL(),user='mpromber',dbname='fai1') # pass seems to be read from ~/.my.cnf
# dsub is a data frame:
dbWriteTable(mycon,"dsub",dsub) # create table "dsub"
dbDisconnect(mycon) # close connection

Time for lunch.