Blog

  • Different behaviors between data frame and matrix in…

    ce contenu Different behaviors between data frame and matrix in R

    > # Generate an artificial matrix > test.m <- matrix(1:6, nrow = 3) > row.names(test.m) <- c('x1', 'x2', 'x3') > col.names(test.m) <- c('a', 'b') Error in col.names(test.m) <- c("a", "b") : could not find function "col.names<-" > > # Generate a data frame from the matrix > test.df <- as.data.frame(test.m) > > > # Selecting elements > ## the row names can be used to select elemnts from a data frame or a matrix > test.idx <- c('x3', 'x1') > test.df[test.idx, ] V1 V2 x3 3 6 x1 1 4 > test.m[test.idx, ] [,1] [,2] x3 3 6 x1 1 4 > > # Selecting elements with index having a name which is not in the data > ## data frame returns NA rows > ## matrix returns an error > test.idx <- c('x4', 'x1') > test.df[test.idx, ] V1 V2 NA NA NA x1 1 4 > test.m[test.idx, ] Error: subscript out of bounds > > > # Duplicate row names > ## duplicate row names are not allowed in data frame. > ## duplicate row names are allowed in matrix. > test.row.names <- c('x1', 'x2', 'x1') > row.names(test.df) <- test.row.names Error in `row.names<-.data.frame`(`*tmp*`, value = c("x1", "x2", "x1")) : duplicate 'row.names' are not allowed In addition: Warning message: non-unique value when setting 'row.names': ‘x1’ > rownames(test.m) <- test.row.names > > # names > ## names() returns column name in data frame > ## names() returns NULL in matrix > names(test.df) [1] "V1" "V2" > names(test.m) NULL

  • Using smooth spline in stat scale in ggplot2…

    Using smooth.spline in stat_scale in ggplot2

    smooth.spline2 <- function(formula, data, ...) { 
      mat <- model.frame(formula, data) 
      smooth.spline(mat[, 2], mat[, 1]) 
    } 
    
    predictdf.smooth.spline <- function(model, xseq, se, level) { 
      pred <- predict(model, xseq) 
      data.frame(x = xseq, y = pred$y) 
    } 
    
    qplot(mpg, wt, data = mtcars) + geom_smooth(method = "smooth.spline2", se= F)
    

    From: http://groups.google.com/group/ggplot2/browse_thread/thread/149dfa0891fe383a

  • Discussions about workflow using LaTeX PDF and textfile…

    Discussions about workflow using LaTeX, PDF, and textfile for collaborations with non-TeX users.

    http://tex.stackexchange.com/questions/1517/workflow-for-reviewing-pdfs-generated-from-tex
    http://tex.stackexchange.com/questions/16367/convert-tex-to-non-tex-and-back
    http://tex.stackexchange.com/questions/16367/convert-tex-to-non-tex-and-back/16406#16406

  • Lineno package which makes LaTeX and PDF reviews…

    Lineno package, which makes LaTeX and PDF reviews easier by printing line numbers.

    http://ctan.mackichan.com/macros/latex/contrib/ednotes/ulineno.pdf

  • Review PDF file with multi reviewers http crocodoc…

    Review PDF file with multi-reviewers.

    http://crocodoc.com/

  • synctex keys Ctrl click

    synctex keys

    Ctrl-click
    
  • Formatting text in Vim

    The gq{motion} command will format a section of text. The ip motion selects the current paragraph, so gqip applies formatting to the current paragraph. Running the gq command moves the cursor to the end of the paragraph. If you want to keep the cursor on the same word, you can instead run the command gw.

    http://vimcasts.org/episodes/hard-wrapping-text/

  • Moving easier around softwrapped text in VIM Put…

    Moving easier around softwrapped text in VIM.
    Put this in the .vimrc.

    "Show elipsis for softwrapped lines
    " Unicode for elipsis: ctrl-v v 2026
    set showbreak=…
    
    "Moving softwrapped lines
    vmap  gj
    vmap  gk
    vmap  g$
    vmap  g^
    vmap  g^
    nmap  gj
    nmap  gk
    nmap  g$
    nmap  g^
    nmap  g^
    

    Adapted from http://vimcasts.org/episodes/soft-wrapping-text/

  • Quick round up of tmux commands Command line…

    Quick round up of tmux commands

    Command line options
    List session and attach a session

    tmux ls
    tmux attach -t target_session
    

    Kill a session

    tmux kill-session -t target_session
    

    In tmux session,
    Ctrl-b c: create a new window
    Ctrl-b s: list sessions
    Ctrl-b w: list windows
    Ctrl-b &: kill the current window
    Ctrl-b x: kill the current pane
    Ctrl-b d: detach from the current session

  • tmux The terminal multiplexer In simple words it…

    tmux; The terminal multiplexer. In simple words, it divides a terminal into many sessions, windows and panes. An interesting usage is the session can be detached and re-attached, which is very useful to connect remotely. Because unexpected disconnection does not kill the process running. Also, dividing a terminal window into many panes is convenient when connected through PuTTy to maximize the screen real estate.

    Nice summary of commands and keys can be found here.

    http://www.dayid.org/os/notes/tm.html
    http://blog.hawkhost.com/2010/06/28/tmux-the-terminal-multiplexer/
    http://blog.hawkhost.com/2010/07/02/tmux-%E2%80%93-the-terminal-multiplexer-part-2/