chu8129 > class(weatherdata$V1[1]) [1] "character" > weatherdata$V1[1:5] [1] "2014/8/1" "2014/8/2" "2014/8/3" "2014/8/4" "2014/8/5" > class(weatherdata$V1[1]) [1] "character" > 怎么用正则截取月份数据,就是//中间的数字 希望结果是: 2014/8/1,2014,08,01 最好是利用正则,以后处理可能更坑爹 另外希望给下split的
ryo > wd <- c('2014/8/1','2014/8/2','2014/8/3','2014/8/4','2014/8/5') > > do.call(rbind,lapply(strsplit(wd,'/'),paste0,collapse=',')) [,1] [1,] "2014,8,1" [2,] "2014,8,2" [3,] "2014,8,3" [4,] "2014,8,4" [5,] "2014,8,5"
9lotus wd <- c('2014/8/1','2014/8/2','2014/8/3','2014/8/4','2014/8/5') sapply(strsplit(wd, '/'), '[', 2)
ryo [未知用户] > sapply(strsplit(wd, '/'), '[', 2) [1] "8" "8" "8" "8" "8" > sapply(strsplit(wd, '/'), function(x) x[2]) [1] "8" "8" "8" "8" "8" 看过但忘了用法,多谢温习一下 “[” 符号。 ;-)