• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

R语言中字符串截取函数截取字符串


Recommended Posts

1、

aaabbbcccddd '

substr(a,1,2) ##提取字符串a的前两个字符串

[1]“aa”

aaabbbcccddd '

substr(a,3,5) ## 3-5字符

[1]“abb”

substr(a,5,nchar(a)) ## 5-最后一个字符

[1]"bbcccddd "

substr(a,nchar(a)-1,nchar(a)) ##提取最后2个字符

[1]“DD”

a - c('abcdef ',' 1234567 ',' ABCDEFG ')

a

[1] 'abcdef' '1234567' 'ABCDEFG '

substr(a,1,3) ##同样适用于向量

[1]《美国广播公司》第123页《ABC》

substr(a,3,5)

[1]《CDE》第345卷《CDE》

substr(a,3,nchar(a))

[1] 'cdef' '34567' 'CDEFG '

substr(a,nchar(a) -2,nchar(a))

[1]《def》567《EFG》

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now