차기작 : R을 배우자
and R
quantlab
2014. 2. 15. 10:00
#01 search() ls() ls(pos=2) #02 help(abs) ?abs #03 5 %% 2 7 %% 3 #04 increment=function(x) { x+1 } #05 sent = "I'm feeling good." sent = "I\'m feeling good." sent = 'I\'m feeling good.' #06 print(paste(c("ba",rep("na",2),"muffin."), collapse="")) #07 age=readline("How old are you?") #cat("How old are you?"); age=scan(what=numeric(), nmax=1) #08 comp=function(n) { ifelse(n>100, "More than 100.", ifelse(n>10, "10<n<=100.","n<=10.")) } #09 grepl('mile','smiles') grepl('smiles','mile') #10 nchar('Hello') #11 s='Call Me Maybe' substring(s, 13, 13) # in R, index starts from 1 substring(s, nchar(s), nchar(s)) substring(s, 1, 4) paste(substring(s, 1, nchar(s)-5),"Perhaps",sep="") #12 regexpr("function",s) # s.find("function") length(gregexpr("function",s)[[1]]) # s.count("function") tolower(s) #13 for (vowel in c('a','e','i','o','u')) { print(vowel) } #14 num=6 while (num>0) { print(num); num=num-1 } #15 temperature = list(18, 20, 22.5, 24) temperature[[4]] temperature[4] #16 length(list("math")) nchar("math") #17 grades=list(80, 90, 70) grades <- c(grades, 3) #grades[[length(grades)+1]] = 3 grades[[length(grades)]]; grades[[length(grades)]]=NULL grades=list(99, 77); append(grades, grades2) grades[grades == 70] = NULL #18 grades=list(80,70,60,90) grades=as.list(sort(unlist(grades))) #19 seq(1,10,2) # range(1,10,2) lst=list(1,2,3) seq(lst) # range(len(lst)) #20 lst=list(list(10,20),list(15),list(40,22)) total=0 for (sublist in lst) { for (num in sublist) total=total+num } #21 cat_string = readLines("cat.txt") cat_string = paste(cat_string, collapse="\n") #22 getwd() #23 setwd("tempDir")