It's possible, but it depends on how you want the data to be formatted. You can use split
to convert the returned data.frame into a list, and then you could collapse the list into a row-wise structure.
As an example I'll just use some fake data.
> thedf <- data.frame(UNIPTROTKB = rep(c("Q12345", "R4534", "T96874"), c(3,1,5)), KEGG = paste0("hsa:", c(1, 12, 123, 1234, 12345, 2345, 234, 432, 44323)))
> thedf
UNIPTROTKB KEGG
1 Q12345 hsa:1
2 Q12345 hsa:12
3 Q12345 hsa:123
4 R4534 hsa:1234
5 T96874 hsa:12345
6 T96874 hsa:2345
7 T96874 hsa:234
8 T96874 hsa:432
9 T96874 hsa:44323
That seems suitably fake, no? Now split
into a list.
> thelst <- split(thedf[,2], thedf[,1])
> thelst
$Q12345
[1] "hsa:1" "hsa:12" "hsa:123"
$R4534
[1] "hsa:1234"
$T96874
[1] "hsa:12345" "hsa:2345" "hsa:234" "hsa:432" "hsa:44323"
And we can do something like
> data.frame(UNIPROTKB = names(thelst), KEGG = do.call(c, lapply(thelst, paste, collapse = ", ")))
UNIPROTKB KEGG
Q12345 Q12345 hsa:1, hsa:12, hsa:123
R4534 R4534 hsa:1234
T96874 T96874 hsa:12345, hsa:2345, hsa:234, hsa:432, hsa:44323
Which is sort of bootleg. We can be more modern by
> library(S4Vectors)
> DataFrame(UNIPROTKB = names(thelst), KEGG = as(thelst, "CharacterList"))
DataFrame with 3 rows and 2 columns
UNIPROTKB KEGG
<character> <CharacterList>
Q12345 Q12345 hsa:1,hsa:12,hsa:123
R4534 R4534 hsa:1234
T96874 T96874 hsa:12345,hsa:2345,hsa:234,...
But it all depends on what you are planning on doing with these data...
. .