Try this:
r <- strsplit(as.character(x$v1), "/")
cbind(unlist(r), rep(x$v2, sapply(r, length)))
On Mon, Jul 20, 2009 at 5:46 PM, Ben Mazzotta
wrote:
> Hello,
>
> I have a dataset with multiple entries in one field separated by "/"
> characters. (The true dataset has long names, 20-odd variables
try this:
> x
v1 v2
1 A L
2 A/B M
3 C N
4 D/E/F O
5 A P
6 C L
> as.data.frame(do.call(rbind, apply(x, 1, function(.row){
+ cbind(strsplit(.row[1], '/')[[1]], .row[2])
+ })),row.names='')
V1 V2
1 A L
2 A M
3 B M
4 C N
5 D O
6 E O
7 F O
8 A P
9 C
Hello,
I have a dataset with multiple entries in one field separated by "/"
characters. (The true dataset has long names, 20-odd variables, and
hundreds of observations.)
v1 v2
1 A L
2 A/B M
3 C N
4 D/E/F O
5 A P
6 C L
What I would like is to have a dataset that lo
3 matches
Mail list logo