http://la-saponniere.fr/1970/01/01/code-bonus-sans-dépôt-boo-casino-50-free-spins/ Remove NA from data in R
A <- na.omit(A)
http://la-saponniere.fr/1970/01/01/code-bonus-sans-dépôt-boo-casino-50-free-spins/ Remove NA from data in R
A <- na.omit(A)
Difference using names or entries in a column selecting elements from data frame.
Use names to select elements from data frame, if possible.
When using the names, the slicing index does not need to the the same length as the data,
but if one of the column is used, the index and the data should be the same length.
Example
test.df <- data.frame(cbind(letters[1:3], 1:3, 4:6) row.names(test.df) <- letters[1:3]
# When the length of the index is different from the number of row of the data frame, it does not work. test.idx <- c('a', 'c') test.df[test.idx, ] test.df[test.df[[[1]], ]
# When the length of the index is the same as the row of the data frame, it works test.idx <- c('a', 'b', 'c') test.df[test.idx, ] test.df[test.df[[[1]], ]
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
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
synctex keys
Ctrl-click
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 vmapgj 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 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 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/
Showing the document statistics
Select a text block.
g and Ctrl-g
Keep the cursor in the middle of the screen in Vi
set scrolloff=10
The command keeps the cursor in the area which is off 10 lines from the top and 10 lines from the bottom.
If the number is big enough, then the cursor stays in the middle while typing.
set so=100
The exception is at the beginning and the end of a file where the cursor moves to the first or the last line.