R语言备忘录
一、基础知识
- R语言如何多行注释或去除注释?
答:选中需要注释的多行R代码后Ctrl + Shift + C
- 如何多行缩进?
答:选中需要缩进的多行R代码后按Tab
键即可。 - 如何多行去除缩进?
答:选中需要缩进的多行R代码后按Shift + Tab
键即可。 - Ubuntu中无法在rstudio上输入汉字?
答:这是因为在rstudio中没法使用搜狗拼音的原因,但可以在rstudio server中输入汉字。注意,rstudio server与rstudio desktop使用相同的R内核,所以两者不要同时打开。 - 可以通过
library()
函数加载包,如果要去除这种加载呢?
答:可以使用detach()
函数。 - R中如何执行cmd或shell命令
cmd <- "dir"
system(cmd)
二、R在微生物生态学分析中的应用
- 如何将无根树转换为有根树用于计算unifrac距离?
答:
library(ape)
phy=multi2di(phy1)
multi2di()
transforms all multichotomies into a series of dichotomies with one (or several) branch(es) of length zero.
di2multi()
deletes all branches smaller than tol and collapses the corresponding dichotomies into a multichotomy.