Dear jonathanbriggs,
Try
x <- read.table(textConnection("CustID itemID
1 a
1 b
2 c
3 a
3 c"),header=TRUE)
closeAllConnections()
with(x, tapply(CustID, itemID, paste, collapse=",") )
# a b c
# "1,3" "1" "2,3"
with(x, tapply(itemID, CustID, paste, collapse=",") )
# 1 2 3
#"a,b" "c" "a,c"
HTH,
Jorge
On Sun, Jun 7, 2009 at 1:26 PM, jonathanbriggs <[email protected]>wrote:
>
> Apologies if this is an obvious question but I am teaching myself R and the
> occasional push in the right direction is much appreciated?
>
> I have a data.frame containing data that looks like this
>
> CustID itemID
> 1 a
> 1 b
> 2 c
> 3 a
> 3 c
>
> I want to assemble the vector of all the items bought by a particular
> customer and can't quite see how to do it.
>
> What is the best way to represent the answers for a single customer and by
> all customers?
>
> Thanks.
> --
> View this message in context:
> http://www.nabble.com/How-do-I-construct-a-one-matrix-from-another--%28newbie%29-tp23913248p23913248.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.