haotu : an open lab notebook

2018/02/26

replace NA with values from other columns

Filed under: R, R Stats — Tags: , , — S @ 01:27
slf2$Year[is.na(slf2$Year)] <- slf2$Ano[is.na(slf2$Year)]
data <- data.frame('a' = c('A','B','C','D','E'),
 'x' = c(1,2,NA,NA,NA),
 'y' = c(NA,NA,3,NA,NA),
 'z' = c(NA,NA,NA,4,5))

cbind(data[1], mycol = na.omit(unlist(data[-1])))

 

https://stackoverflow.com/questions/14563531/combine-column-to-remove-nas

2018/02/24

set working directory R notebook, markdown

Filed under: R, R Markdown — Tags: , , — S @ 00:08
```{r "setup", include=FALSE}
library(knitr)
opts_knit$set(root.dir = "~/mydir")
```

https://philmikejones.wordpress.com/2015/05/20/set-root-directory-knitr/

2018/02/01

R Markdown Resources

Filed under: R, R Markdown, R Stats — Tags: , , , , — S @ 09:10

cheatsheets here https://www.rstudio.com/resources/cheatsheets/

online tutorial

http://rmarkdown.rstudio.com/lesson-1.html

chapter in r for data science

http://r4ds.had.co.nz/r-markdown.html

 

2018/01/31

save the first (or any) element of a string split

Filed under: errors in R, Manipulate Data in R, R, R, R Stats — Tags: , — S @ 06:58
dirs<-matrix(ncol = 2,data=unlist(strsplit(out$`Full Name`,split=",")),byrow = TRUE)[,1]

2018/01/29

Replace . in string in R

Filed under: errors in R, Manipulate Data in R, R, R, R Stats — Tags: — S @ 07:54
gsub(x = ff,pattern = "[.]",replacement="")

2018/01/25

dplyr column names with spaces, how to index

Filed under: Manipulate Data in R, R, R, R Stats — Tags: , , — S @ 09:12

backtick it!

`my name`

https://stackoverflow.com/questions/22842232/dplyr-select-column-names-containing-white-space

2018/01/03

All Pairwise Combinations of Rownames from a Square Matrix

Filed under: R, R, R spatial, R Stats, Uncategorized — Tags: , , , — S @ 12:37
combn(rownames(my.square.matrix), m=2, FUN=paste, collapse = "-", simplify = T)

2017/12/11

read file from parent folder of current working directory

Filed under: Manipulate Data in R, R, R, R Stats, Uncategorized — Tags: , — S @ 08:10

If  your working directory is C:Parent/Child

Then to read a file from Parent use ..

file="../MY_FILE.RData"

https://stackoverflow.com/questions/24319168/how-to-move-backward-parent-folder

2017/07/18

Make ggplot look like base plot in R

Filed under: ggplot, R, R graphics — Tags: , , , , , , — S @ 04:46
myplot + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))
myplot + theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))

here

 

 

 

2017/06/22

Automatic MIT License for R Packages

Filed under: errors in R, R, R Stats — Tags: , — S @ 07:01
devtools::use_mit_license()
« Newer PostsOlder Posts »

Blog at WordPress.com.