R语言学习笔记10-字符串篇

- string
    - grep("Pole",c("Equator","North Pole","South Pole"))
        - 2 3
    - grep("pole",c("Equator","North Pole","South Pole"))
        - integer(0)
    - nchar("South Pole")
        - 10
    - paste("North","Pole",sep="")
        - "NorthPole"
    - i<-8
    - sprintf("the square of %d is %d",i,i^2)    # format print
    - substring("Equator",3,5)    # "uat"
    - strsplit("6-16-2011",split="-")
        - [[1]]
        - "6" "16" "2011"
    - regexpr("uat","Equator")
        - 3
    - grepexpr("iss","Mississippi")
        - 2 5    # find all occurrances
    - grep("[au]",c("Equator","North Pole","South Pole"))
        - 1 3    # word contains a or u
    - grep("o.e",c("Equator","North Pole","South Pole"))
        - 2 3    # word contains o+any char+e
    - grep("\\.",c("abc","de","f.g"))    # escape
        - 3
    - testsuffix<-function(fn,suff) {
        - parts<-strsplit(fn,".",fixed=TRUE)    # or strsplit(fn,"\\.")
        - nparts<-length(parts[[1]])    # split length
        - return(parts[[1]][nparts]==suff)
    - }

你可能感兴趣的:(R语言学习笔记10-字符串篇)