Re: [R] how to sort and plot data?
Try looking at the examples in : ?order perhaps: dta.frm[order(user_id), ] especially the one that demonstrates how to sort dataframes with three indices. And if that does not satisfy your needs, then you absolutely must provide a simple example and an explicit layout of what the output should look like. -- David Winsemius On Apr 5, 2009, at 11:01 PM, Hemavathi Ramulu wrote: hi Erin, Thanks for your reply to my problems. I tried and it works, but it sorted all the column. In my case, I want it to sort d user_id column and another information in other column will follow it. Now, after I sorted, the information which website viewed by user was wrong. I want to as how we can sort or filter in excel. Thank you. regards, hema On Fri, Apr 3, 2009 at 4:44 PM, Umesh Srinivasan umesh.sriniva...@gmail.com wrote: 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 dieter.me...@menne-biomed.dewrote: Hem wrote: user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google0940 ... 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. __ R-help@r-project.org 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]] __ R-help@r-project.org 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]] __ R-help@r-project.org 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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org 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.
Re: [R] how to sort and plot data?
Hi r-help-boun...@r-project.org napsal dne 06.04.2009 05:01:56: hi Erin, Thanks for your reply to my problems. I tried and it works, but it sorted all the column. In my case, I want it to sort d user_id column and another information in other column will follow it. Now, after I sorted, the information which website viewed by user was wrong. I want to as how we can sort or filter in excel. If you want to sort and filter like in excel why not using excel rowSums(table(test$user_id, test$website)) gives you info how many of websites were visited by each user_id. It is not clear how days are coded so it is difficult to come with any reasonable way how to compute numbers per day. I would try to split/lapply way but there could be better means. Regards Petr Thank you. regards, hema On Fri, Apr 3, 2009 at 4:44 PM, Umesh Srinivasan umesh.sriniva...@gmail.com wrote: 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 dieter.me...@menne-biomed.dewrote: Hem wrote: user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google0940 ... 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. __ R-help@r-project.org 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]] __ R-help@r-project.org 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]] __ R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] how to sort and plot data?
Hema, This may work: aggregate(hema[1],hema[2],function(x)length(unique(x))) to calculate how many different websites each id visited. hema[1] is the website column, hema[2] is user_id. You can always add more index columns like days to aggregate(). Jun On Thu, Apr 2, 2009 at 11:06 PM, Hemavathi Ramulu hema.ram...@gmail.comwrote: hi, Previously my email very simple and less information. Let say I have raw data as below:- user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google0940 60yahoo1050 40friendster1115 61google1200 40friendster1215 25google1030 28youtube 0830 30facebook0945 This data described about particular website viewed by particular ID in one day. My problem is how to sort the data? So that, I can get information about one user_id viewed how many website perday? secondly, I want to plotted above data where x-axis (user_id) and y-axis(website). Actually, im new to R-project and still in learning process. So, I really want you all help. Thank you and I really appreciate everyone feedback. regards, Hema. [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Jun Shen PhD PK/PD Scientist BioPharma Services Millipore Corporation 15 Research Park Dr. St Charles, MO 63304 Direct: 636-720-1589 [[alternative HTML version deleted]] __ R-help@r-project.org 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.
Re: [R] how to sort and plot data?
hi Erin, Thanks for your reply to my problems. I tried and it works, but it sorted all the column. In my case, I want it to sort d user_id column and another information in other column will follow it. Now, after I sorted, the information which website viewed by user was wrong. I want to as how we can sort or filter in excel. Thank you. regards, hema On Fri, Apr 3, 2009 at 4:44 PM, Umesh Srinivasan umesh.sriniva...@gmail.com wrote: 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 dieter.me...@menne-biomed.dewrote: Hem wrote: user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google0940 ... 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. __ R-help@r-project.org 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]] __ R-help@r-project.org 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]] __ R-help@r-project.org 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.
Re: [R] how to sort and plot data?
Hem wrote: user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google0940 ... 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. __ R-help@r-project.org 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.
Re: [R] how to sort and plot data?
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 dieter.me...@menne-biomed.dewrote: Hem wrote: user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google0940 ... 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. __ R-help@r-project.org 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]] __ R-help@r-project.org 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.
[R] how to sort and plot data?
hi, Previously my email very simple and less information. Let say I have raw data as below:- user_id website time 20google0930 21yahoo0935 20facebook1000 25facebook1015 61google0940 60yahoo1050 40friendster1115 61google1200 40friendster1215 25google1030 28youtube 0830 30facebook0945 This data described about particular website viewed by particular ID in one day. My problem is how to sort the data? So that, I can get information about one user_id viewed how many website perday? secondly, I want to plotted above data where x-axis (user_id) and y-axis(website). Actually, im new to R-project and still in learning process. So, I really want you all help. Thank you and I really appreciate everyone feedback. regards, Hema. [[alternative HTML version deleted]] __ R-help@r-project.org 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.