, . , , .
data.frame(id=unique(my.data$id), my.string=sapply(lapply(unique(my.data$id), function(id) gsub('^$','.',substr(gsub('\\.','',do.call(paste0,strsplit(my.data[my.data$id==id,'my.string'],''))),1,1)) ), function(x) paste0(x,collapse='') ), stringsAsFactors=F );
, :
lapply():
lapply(unique(my.data$id), function(id) ... )
, data.frame, . :
gsub('^$','.',substr(gsub('\\.','',do.call(paste0,strsplit(my.data[my.data$id==id,'my.string'],''))),1,1))
, :
strsplit(my.data[my.data$id==id,'my.string'],'')
my.string id strsplit(). list , , , . , , .
, ( id == 2):
[[1]]
[1] "1" "1" "." "." "." "." "." "." "." "." "." "." "." "." "." "." "." "." "." "."
[[2]]
[1] "." "1" "." "." "." "2" "." "." "." "." "." "." "." "." "." "." "." "." "." "."
[[3]]
[1] "." "." "." "." "." "2" "." "." "." "3" "." "." "." "." "." "." "." "." "." "."
strsplit() ( ..., ):
do.call(paste0,...)
paste0() , , strsplit() . , , , :
[1] "1.." "11." "..." "..." "..." ".22" "..." "..." "..." "..3" "..." "..." "..." "..." "..." "..." "..." "..." "..." "..."
paste0() :
gsub('\\.','',...)
, - , :
[1] "1" "11" "" "" "" "22" "" "" "" "3" "" "" "" "" "" "" "" "" "" ""
gsub() :
substr(...,1,1)
, , , . , , .
substr() :
gsub('^$','.',...)
, , , , . , id == 2:
[1] "1" "1" "." "." "." "2" "." "." "." "3" "." "." "." "." "." "." "." "." "." "."
, lapply(). , list , . , , , :
sapply(..., function(x) paste0(x,collapse='') )
sapply() (simplify-apply) , , :
[1] "11...2...3.........." "...................." "......2.....2...4..." ".1...2....3..34....." "....1.....12....3..." "..................44" ".2.......2.........." "...2...2.....2...2.."
, , , data.frame, data.frame:
data.frame(id=unique(my.data$id), my.string=..., stringsAsFactors=F )
:
id my.string
1 2 11...2...3..........
2 5 ....................
3 6 ......2.....2...4...
4 7 .1...2....3..34.....
5 8 ....1.....12....3...
6 9 ..................44
7 10 .2.......2..........
8 11 ...2...2.....2...2..
!