[Bioc-devel] question on annotations and data.frames
Heidi Dvinge
heidi at ebi.ac.uk
Tue Aug 23 14:23:05 CEST 2011
Hi Andreas,
> Dear mailing list,
> let's suggest I have a data.frame full of annotation data. In the first
> column I have Identifiers present in the data. In all other columns I have
> another annotaion for this identifier column.
> However, on some rows there is no 1:1 mapping but let's say a 1:3 mapping
> or something like this:
>
> ID Symbol
> 1 Bla
> 2 Foo
> 3 XYZ // xyz /// xyz01
> 4 abc
>
> I want to "stretch" the line which has multiple annotation tags. I know I
> can split it with "strsplit", this get's me here:
>
> ID Symbol
> 1 Bla
> 2 Foo
> 3 "XYZ" "xyz" "xyz01"
> 4 abc
>
> But how can I get to this:
>
> ID Symbol
> 1 Bla
> 2 Foo
> 3 XYZ
> 3 xyz
> 3 xyz01
> 4 abc
>
>
This isn't particularly elegant, but might get you what you want:
test <- data.frame(A=c("x", "y", "z"), B=c("X", "Y1 // Y2 // Y3", "Z"),
stringsAsFactors=FALSE)
test.split <- strsplit(test$B, " // ", fixed=TRUE)
test2 <- test[rep(1:nrow(test), times=sapply(test.split, length)),]
test2$B <- unlist(test.split)
HTH
\Heidi
> Your help will be really appreciated!
>
> Thanks in advance, Andreas
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> Bioc-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
More information about the Bioc-devel
mailing list