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

Advertisements

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

 

Create a free website or blog at WordPress.com.