Question

My data frame like this:

> mydata
   time  id  product
1 201301  1   apple
2 201302  1     htc
3 201302  1   apple
4 201302  2     htc
5 201302  2   apple

How get the following result?

> result
   time   id   product
1 201301  1     apple
2 201302  1 apple&htc
3 201302  2 apple&htc

I have tried ddply()function like this:

ddply(mydata,.(time,id),summarise,paste0(product,"&",product))

But it doesn't work as my expectation.Thanks for your answers.

And, my point is, how to realize in SQL in SAP HANA DATABASE? Thanks a lot!

Was it helpful?

Solution

you can try this:

 ddply(tab, .(time, id), summarise, product = paste(product, collapse="&"))

hth

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top