R语言中substr函数,字符串截取函数
1、测试1
x <- "dfserut"
x
substr(x,1,3)
substr(x,2,5)
substr(x,2)
substring(x,2)
2、测试2
x <- c("sfwsfs","ydsfs","gdsge","mhxsf")
x
substr(x,1,3)
substring(x,3)
应用于向量
3、测试3
v1 <- c("sfde","fsdf","rere")
v2 <- c("erea","rftg","cfsd")
x <- data.frame(v1,v2)
x
substr(x$v1,1,2)
substring(x$v1,3)
应用于数据框
4、测试4
x <- "dfserut"
x
substr(x,1,3)
substr(x,1,3) <- "ABC"
x
substr(x,1,3) <- "M"
x