博文

向量的内积和距离

图片
向量的内积(点积) sum(a*b) 或者 t(a)%*%b 向量的距离 安装 Rtreemix 包 source("http://bioconductor.org/biocLite.R") biocLite("Rtreemix") L1.dist 计算 L1 距离, cosin.dist 计算余弦距离, euclidian.dist 计算欧氏距离, rank.cor.dist 计算排名相关距离。向量必须有相同的长度。当使用 rank.cor.dist 向量必须有长度大于 4 L1.dist(p, q) cosin.dist(p, q) euclidian.dist(x, y) rank.cor.dist(x, y) 对称正交化 正交矩阵 orthogonal matrix: 正交矩阵P是一个方块矩阵,该矩阵的行和列皆为正交的单位向量。 正交矩阵满足下列性质:P^TP=PP^T=I和P^T=P^{-1} 对称矩阵 symmetric matrix:对称矩阵A是一个方块矩阵,其转置和自身等价,即 A^T=A 对角矩阵 diagonal matrix:主对角线之外的元素皆为0的矩阵,对角线上的元素可以为0,也可以不为0。 正交对角化: 矩阵被称为可正交对角化orthogonally diagonalizable,当且仅当一个正交矩阵P使得P^TAP=D, D是一个对角阵。 特征值 eigenvalue 和特征向量 eigenvectors:当方阵A与一个非零向量v相乘等于一个常数 乘以该向量时,v被称为A的特征向量, 被称为特征值,即Av= v。 AA <- matrix ( c ( 7 , 0 , 9 , 0 , 2 , 0 , 9 , 0 , 7 ) , ncol = 3 ) eigen.A <- eigen ( AA ) #get eigenvalues and eigen vectors lam <- eigen.A$values #特征值默认以降序排列 vecs <- eigen.A$vectors #特征向量对应于降序排列的特征值,如果想改变...

R 返回包含“社区卫生服务中心”数量

图片
men <- read.csv("/home/xuefliang/Downloads/men.csv",header = F) b <- grep("社区卫生服务中心",men$V1) length(b) a <- grepl("社区卫生服务中心",men$V1) #grep仅返回匹配项的下标,而grepl返回所有的查询结果,并用逻辑向量表示有没有找到匹配。windows csv文件ANSI编码需用记事本修改为UTF-8

linux mint语言选项 丢失

sudo apt-get install mintlocale

R on vps tips Setting LC_COLLATE failed, using "C"

sudo apt-get install language-pack-en-base sudo dpkg-reconfigure locales    错误提示 “ Unable to connect to service ”  adduser xuefliang #非root用户组   vi /etc/rstudio/rserver.conf www-port = 8787 rsession-which-r=/usr/bin/R 用rstudio-server verify-installation进行验证     locale::facet::_S_create_c_locale name not valid解决方案    export LC_ALL="C"  

R计算排列和组合

图片
library(combinat) permn(3) length(permn(3)) combn(1000, 2) dim(combn(1000,2))[2] 组合(Combinations)和排列( Permutation )计算公式为 perm = function(n, x) {   return(factorial(n) / factorial(n-x)) } comb = function(n, x) {   return(factorial(n) / (factorial(x) * factorial(n-x))) } 组合数:choose(n, k) 注意:从n个中选出k个 阶乘(k!):factorial(k) 排列数:choose(n, k) * factorial(k)

R 语言求极限

library(rSymPy) sympy("limit(1/x, x, oo)") sympy("limit(1/x, x, 0)") sympy("limit(x*log(x), x, 0)")  sympy("limit(sin(x)/x*x, x, 0)") sympy("limit(exp(x)/x*x, x, 0)") sympy("limit(x**x, x, 0)") sympy("limit(x*exp(1)**-x, x, oo)")  ##**代表幂 sympy("limit((cos(x)-1)/x**2, x, 0)")

ubuntu下安装goldendict及离线词库

1.sudo apt-get install goldendict 2.播放语音 sudo apt-get install mplayer sudo apt-get install ubuntu-restricted-addons sudo apt-get install ubuntu-restricted-extras 3.批量解压离线词库 #! /bin/bash # run this script to install goldendict and off-line dictionaries # Only for Ubuntu # created by longbin <beangr@163.com> # 2014-03-28 function goldendict_essential_install(){     for file in ${FILE_LIST}     do         trap 'echo -e "\nInterrupted by user"; exit' INT         echo -e "\n======================================="         echo -e "Preparing to install ${file} ..."         echo -e "======================================="         echo -e "\tsudo apt-get install ${file}"         sudo apt-get install ${file}     done     RET...