Hi,
There is definitely a more elegant way of doing this which I don't know
about (without a for loop), but try this:

mat <- matrix(NA, nrow = max(user_id), ncol = 2)
mat[,1] <- 1:max(user_id) # 1st column of matrix is the user ID

for (i in 1:max(user_id)){
temp1 <- subset(data, user_id = i)
temp2 <- unique(temp1$website)
mat[2,i] <- length(temp2)
}

The matrix will give you user id and number of sites visited, provided user
id ranges from 1 to the number of users. There must be a way to do this
using table, but I cant figure it out.

Cheers,
Umesh

On Fri, Apr 3, 2009 at 1:42 PM, Dieter Menne
<[email protected]>wrote:

>
>
>
> Hem wrote:
> >
> > user_id  website          time
> > 20        google            0930
> > 21        yahoo            0935
> > 20        facebook        1000
> > 25        facebook        1015
> > 61        google            0940
> > ...
> > My problem is how to sort the data? So that, I can get information about
> > one
> > user_id viewed how many website perday?
> >
> >
>
> Maybe you were looking at the wrong item, because what you want is not
> sorting, but a table.
>
> Check the documentation of table or ftable.
>
> Dieter
>
> --
> View this message in context:
> http://www.nabble.com/how-to-sort-and-plot-data--tp22861661p22863918.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.

Reply via email to