More busy than busy more recently ... Really busy///
As a rookie, do not understand why so easy to forget the basic operation of R, feel more difficult than C # JAVA, and to review again
1 ##数据操作的入门2 3 ##定义一个函数判断偶数4Func <-function (x)5 {6 if(x% 2 = =0) {7RET <-'even'8}Else9 {TenRET <-'Odd' One } A return(ret) - } - the ##测试效果 -Func (35) - - ##sapply----The following code will error, the parameter can only be a numeric value +VEC <-Round (runif (4) * 100) - func (VEC) + ##这样子的代码才是正确的 A sapply (Vec,func) at - ##另外一种方法 -FUNCV <-Vectorize (func) - Funcv (VEC) - - ##还有一种实现方法 IfElse inFuncif <-function (VECC) - { to ##这里的代码比较的机智 + return(IfElse (vecc%%2,'Odd','even')) - } the Funcif (VEC) * $ ##另一个稍微有趣的试验Panax NotoginsengSet.seed (123) -Out <-data.frame (x2 = runif (4) *, X1 = C ('a','b','C','D')) the ##打印输出 + Print(out) AOut <-Format (out,digits = 3) the out + ##paste可以连接两个字符 with cat output -Cat (paste (out$x1,out$x2,sep ='='), Sep ='\ n') $ $ - ##txt文件操作 - ##创建txt theoutfile <-file ('output.txt') - ##cat写入WuyiCat (1:100,sep ='\ t', File =outfile) the Close (outfile) - #write another line, or the last number and the first number will coincide. WuCat'\ t', Sep =' ', File ='output.txt', append =TRUE) - ##cat还可以对已有内容的文件加操作---As to why this is not the direct use of output I am also very surprised AboutCat (101:200,sep ='\ n', File ='output.txt', append =TRUE) $ ##读取txt -Input <-Scan (file ='output.txt') - input - A ##开始一个新的例子 + ##读取路径 thePath <-. libpaths () [1] - ##改路径下的所有文件夹? $Doc.names <-dir (path) the Doc.names the ##改变路径 theDoc.path <-sapply (doc.names,function (names) { thePaste (Path,names,'DESCRIPTION', Sep ='/') - }) in Doc.path the ##生成最终文档 theDoc <-sapply (Doc.path,function (DOC) readlines (DOC)) AboutDoc
Basic operation of the R language-read and write txt,sapply&lapply