Re: [R] list element to matrix
[EMAIL PROTECTED] wrote: I have created a list of matrices using sapply or lapply and wish to extract each of the matrices as a matrix. Some of them are 2x2, 3x3, etc. I can do this one at a time as: M1-as.matrix(D[[1]]) How can repeat this process for an unknown number of entries in the list? In other words, how shall I index M1? Hi Diana, To step through the matrices in your list (assuming that it only has one level): for(mat in 1:length(D)) { do what you want } Jim __ R-help@stat.math.ethz.ch 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] list element to matrix
I have created a list of matrices using sapply or lapply and wish to extract each of the matrices as a matrix. Some of them are 2x2, 3x3, etc. I can do this one at a time as: M1-as.matrix(D[[1]]) How can repeat this process for an unknown number of entries in the list? In other words, how shall I index M1? Diana __ R-help@stat.math.ethz.ch 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] list element to matrix
You get the number of list elements with length(D), the dimensions of M1 with dim(M1) see help with: ?dim ?length Hope this helps... I have created a list of matrices using sapply or lapply and wish to extract each of the matrices as a matrix. Some of them are 2x2, 3x3, etc. I can do this one at a time as: M1-as.matrix(D[[1]]) How can repeat this process for an unknown number of entries in the list? In other words, how shall I index M1? Diana -- Friedrich Schuster [EMAIL PROTECTED] Tel.: +49 6221 737474 Tel.: +49 163 7374744 __ R-help@stat.math.ethz.ch 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] list element to matrix
If they are already a matrix in the list, then you don't have to use 'as.matrix'; you can just say: M1 - D[[1]] Now the question is, what do you mean by how do you index M1? Do you want to go through the list applying a function to each matrix? If so, then just 'lapply'. For example, to get the column means, you would do: mean.list - lapply(D, colMeans) Can you explain in a little more detail the problem you are trying to solve. On 9/5/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I have created a list of matrices using sapply or lapply and wish to extract each of the matrices as a matrix. Some of them are 2x2, 3x3, etc. I can do this one at a time as: M1-as.matrix(D[[1]]) How can repeat this process for an unknown number of entries in the list? In other words, how shall I index M1? Diana __ R-help@stat.math.ethz.ch 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch 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] list
Hello, in using vector() we can create a vector and fill in like this v - vector() v - c(v,2) v - c(v,c(5,10,23)) but I wanna know if it's possible to do the same with the list I don't fond how? Can you help me? Thanks. ___ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] list
'c' also works with lists: a=list(1,2,3) b=list(1,2,3) c(a,b) [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 3 [[4]] [1] 1 [[5]] [1] 2 [[6]] [1] 3 On 7/18/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote: Hello, in using vector() we can create a vector and fill in like this v - vector() v - c(v,2) v - c(v,c(5,10,23)) but I wanna know if it's possible to do the same with the list I don't fond how? Can you help me? Thanks. ___ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Christophe Pallier (http://www.pallier.org) [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] list
hello, I wanna know how to create a list of list if it's possible and if it isn't possible how to do without. thanks. _ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] list
There's no special method, just create a list in the usual way. For example: l1-list(a=letters[1:5],b=letters[6:10]) l1 $a [1] a b c d e $b [1] f g h i j l2-list(c=LETTERS[1:5],d=LETTERS[6:10]) l2 $c [1] A B C D E $d [1] F G H I J l3-list(l1,l2) l3 [[1]] [[1]]$a [1] a b c d e [[1]]$b [1] f g h i j [[2]] [[2]]$c [1] A B C D E [[2]]$d [1] F G H I J On 06/06/07, elyakhlifi mustapha [EMAIL PROTECTED] wrote: hello, I wanna know how to create a list of list if it's possible and if it isn't possible how to do without. thanks. _ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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 Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ R-help@stat.math.ethz.ch 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] list
Sure you can. list(list(), list(), list()) library(fortunes) fortune(Yoda) Evelyn Hall: I would like to know how (if) I can extract some of the information from the summary of my nlme. Simon Blomberg: This is R. There is no if. Only how. -- Evelyn Hall and Simon 'Yoda' Blomberg R-help (April 2005) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens elyakhlifi mustapha Verzonden: woensdag 6 juni 2007 10:59 Aan: R-help@stat.math.ethz.ch Onderwerp: [R] list hello, I wanna know how to create a list of list if it's possible and if it isn't possible how to do without. thanks. __ ___ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] list
--- elyakhlifi mustapha [EMAIL PROTECTED] wrote: hello, I wanna know how to create a list of list if it's possible and if it isn't possible how to do without. thanks. Why? The question is not clear and could mean several things. Can you explain a bit? __ R-help@stat.math.ethz.ch 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] List filtration
Hello R-ologists, Imagine you have a list list like so: list [[1]] [1] IPI00776145.1 IPI00776187.1 [[2]] [1] Something IPI00807764.1 IPI00807887.1 [[3]] [1] IPI00807764.1 [[4]] [1] Somethingelse What I need to achieve is a filtered list list2 like so: list2 [[1]] [1] IPI00776145.1 [[2]] [1] IPI00807764.1 [[3]] [1] IPI00807764.1 So: - if sublist-entry 1 start with ^IPI make it the list-entry. - otherwise chose the first ^IPI sublist-entry present. - delete the list-entry if not ^IPI sublist-entry present. Can anybody nudge me towards an elegant solution without looping - I have LOTS of entries to process ... Thanks for your Teachings, Joh __ R-help@stat.math.ethz.ch 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] List filtration
try this: lis. - lapply(lis, function(x) if (length(ind - grep(^IPI, x))) x[ind[1]] else NULL) lis.[!sapply(lis., is.null)] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Johannes Graumann [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, February 22, 2007 3:33 PM Subject: [R] List filtration Hello R-ologists, Imagine you have a list list like so: list [[1]] [1] IPI00776145.1 IPI00776187.1 [[2]] [1] Something IPI00807764.1 IPI00807887.1 [[3]] [1] IPI00807764.1 [[4]] [1] Somethingelse What I need to achieve is a filtered list list2 like so: list2 [[1]] [1] IPI00776145.1 [[2]] [1] IPI00807764.1 [[3]] [1] IPI00807764.1 So: - if sublist-entry 1 start with ^IPI make it the list-entry. - otherwise chose the first ^IPI sublist-entry present. - delete the list-entry if not ^IPI sublist-entry present. Can anybody nudge me towards an elegant solution without looping - I have LOTS of entries to process ... Thanks for your Teachings, Joh __ R-help@stat.math.ethz.ch 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch 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] List filtration
On Thu, 2007-02-22 at 15:33 +0100, Johannes Graumann wrote: Hello R-ologists, [snip] So: - if sublist-entry 1 start with ^IPI make it the list-entry. - otherwise chose the first ^IPI sublist-entry present. - delete the list-entry if not ^IPI sublist-entry present. One way to do it would be: l - list(c(IPI00776145.1, IPI00776187.1), c(Something, IPI00807764.1, IPI00807887.1), c(IPI00807764.1), c(Somethingelse)) f - function(x) { r - grep(^IPI, x, value=TRUE) if (length(r) 0) return(r[1]) else return(NA) } l2 - unlist(lapply(l, f)) l2 - l2[!is.na(l2)] But I'm sure that more elegant solutions will be posted --- Rajarshi Guha [EMAIL PROTECTED] GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE --- Writing software is more fun than working. __ R-help@stat.math.ethz.ch 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] List filtration
Thanks for your help! Joh Dimitris Rizopoulos wrote: try this: lis. - lapply(lis, function(x) if (length(ind - grep(^IPI, x))) x[ind[1]] else NULL) lis.[!sapply(lis., is.null)] I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Johannes Graumann [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Thursday, February 22, 2007 3:33 PM Subject: [R] List filtration Hello R-ologists, Imagine you have a list list like so: list [[1]] [1] IPI00776145.1 IPI00776187.1 [[2]] [1] Something IPI00807764.1 IPI00807887.1 [[3]] [1] IPI00807764.1 [[4]] [1] Somethingelse What I need to achieve is a filtered list list2 like so: list2 [[1]] [1] IPI00776145.1 [[2]] [1] IPI00807764.1 [[3]] [1] IPI00807764.1 So: - if sublist-entry 1 start with ^IPI make it the list-entry. - otherwise chose the first ^IPI sublist-entry present. - delete the list-entry if not ^IPI sublist-entry present. Can anybody nudge me towards an elegant solution without looping - I have LOTS of entries to process ... Thanks for your Teachings, Joh __ R-help@stat.math.ethz.ch 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] list of data frame objects
Hi Folks, I need to extract the list of all my data frame objects. With objects() I can list all objects and was hoping to use something like the following: objects()[is.data.frame(objects())] to extracts all my objects that are data frame... What am I doing wrong? Thanks - Tim - Any questions? Get answers on any topic at Yahoo! Answers. Try it now. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] list of data frame objects
try something like the following (untested): objs - ls() sapply(objs, function(obj) inherits(get(obj), data.frame)) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting Tim McDonald [EMAIL PROTECTED]: Hi Folks, I need to extract the list of all my data frame objects. With objects() I can list all objects and was hoping to use something like the following: objects()[is.data.frame(objects())] to extracts all my objects that are data frame... What am I doing wrong? Thanks - Tim - Any questions? Get answers on any topic at Yahoo! Answers. Try it now. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch 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] List-manipulation
Hi, Sorry for the question, I know it should be basic knowledge but I'm struggling for two hours now. How do I select only the first entry of each list member and ignore the rest? So for $121_at -113691170 $1255_g_at 42231151 $1316_at 35472685 35472588 $1320_at -88003869 I only want to select -113691170, 42231151, 35472685 and -88003869 .? Regards Benjamin -- Benjamin Otto Universitaetsklinikum Eppendorf Hamburg Institut fuer Klinische Chemie Martinistrasse 52 20246 Hamburg [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] List-manipulation
Is this what you want? x - list(a=1:3, b=30:34, c=40:35) x $a [1] 1 2 3 $b [1] 30 31 32 33 34 $c [1] 40 39 38 37 36 35 lapply(x,'[', 1) $a [1] 1 $b [1] 30 $c [1] 40 unlist(lapply(x,'[', 1)) a b c 1 30 40 On 9/29/06, Benjamin Otto [EMAIL PROTECTED] wrote: Hi, Sorry for the question, I know it should be basic knowledge but I'm struggling for two hours now. How do I select only the first entry of each list member and ignore the rest? So for $121_at -113691170 $1255_g_at 42231151 $1316_at 35472685 35472588 $1320_at -88003869 I only want to select -113691170, 42231151, 35472685 and -88003869 .? Regards Benjamin -- Benjamin Otto Universitaetsklinikum Eppendorf Hamburg Institut fuer Klinische Chemie Martinistrasse 52 20246 Hamburg [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch 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] List-manipulation
You need one of the apply family of functions. ?sapply tmp - list(a=1:2, b=3:5, c=5, dd=numeric(0), e=1:8) sapply(tmp, function(x) x[1]) a b c dd e 1 3 5 NA 1 __ R-help@stat.math.ethz.ch 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] List-manipulation
Does this do what you want? x - list(1,2,3:7,8,9:10) sapply(x, function(xx) xx[1]) [1] 1 2 3 8 9 -- Tony Plate Benjamin Otto wrote: Hi, Sorry for the question, I know it should be basic knowledge but I'm struggling for two hours now. How do I select only the first entry of each list member and ignore the rest? So for $121_at -113691170 $1255_g_at 42231151 $1316_at 35472685 35472588 $1320_at -88003869 I only want to select -113691170, 42231151, 35472685 and -88003869 .? Regards Benjamin -- Benjamin Otto Universitaetsklinikum Eppendorf Hamburg Institut fuer Klinische Chemie Martinistrasse 52 20246 Hamburg [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] list of lists to a data.frame
Hi, I have a situation where I have a list of lists. Each list can contain elements of different types (but each one will be a scalar) say of double, integer or character. However the elements of each list are always in the same order: x - list('a', 1, 2) y - list('b', 3, 4) z - list('c', 5, 6) a - list(x,y,z) What I'd like to do is to convert a to a data.frame. Currently I am doing: b - do.call(rbind, a) However, when I do b[,1] I get a list returned rather than a vector of characters and similarly for b[,2] and so on. I am clearly missing something, but how do I convert the list of lists to a data.frame where a column is represented as a vector rather than a list? Thanks, --- Rajarshi Guha [EMAIL PROTECTED] GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE --- All life evolves by the differential survival of replicating entities. -- Dawkins __ R-help@stat.math.ethz.ch 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] list of lists to a data.frame
On Fri, 2006-08-18 at 16:44 -0400, Rajarshi Guha wrote: Hi, I have a situation where I have a list of lists. Each list can contain elements of different types (but each one will be a scalar) say of double, integer or character. However the elements of each list are always in the same order: x - list('a', 1, 2) y - list('b', 3, 4) z - list('c', 5, 6) a - list(x,y,z) What I'd like to do is to convert a to a data.frame. Currently I am doing: b - do.call(rbind, a) However, when I do b[,1] I get a list returned rather than a vector of characters and similarly for b[,2] and so on. I am clearly missing something, but how do I convert the list of lists to a data.frame where a column is represented as a vector rather than a list? Thanks, How about: as.data.frame(sapply(a, rbind)) V1 V2 V3 1 a b c 2 1 3 5 3 2 4 6 or: as.data.frame(t(sapply(a, rbind))) V1 V2 V3 1 a 1 2 2 b 3 4 3 c 5 6 depending upon how you wanted the columns versus rows to be structured. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch 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] list to balanced array
I am working with a large data set of arrivals, for each day I have aggregated the arrivals into hrs (1-24) via: apply(x,2,table). On some days there are zero arrivals during some hours of the day, this leaves me with (I believe) a list of vectors of differnt lengths (see below). [[4]] 1 2 3 5 6 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24 1 3 2 3 1 1 2 3 4 4 4 3 2 6 2 5 1 2 2 2 1 [[5]] 2 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 2 1 1 2 1 5 3 6 6 3 2 2 1 4 3 3 4 2 1 I would like to be able to create an array with equal numbers of rows (24) for each column, i.e., fill in the gaps with Zeros. [[5]] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 0 2 0 0 1 1 0 2 1 5 3 6 6 3 2 2 1 4 3 0 3 4 2 1 Any suggestions? thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] list to balanced array
try the following: arrivals - matrix(sample(1:24, 100, TRUE), 10, 10) apply(arrivals, 2, function(x) table(factor(x, levels = 1:24))) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Spencer Jones [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Wednesday, August 16, 2006 5:22 PM Subject: [R] list to balanced array I am working with a large data set of arrivals, for each day I have aggregated the arrivals into hrs (1-24) via: apply(x,2,table). On some days there are zero arrivals during some hours of the day, this leaves me with (I believe) a list of vectors of differnt lengths (see below). [[4]] 1 2 3 5 6 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23 24 1 3 2 3 1 1 2 3 4 4 4 3 2 6 2 5 1 2 2 2 1 [[5]] 2 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 2 1 1 2 1 5 3 6 6 3 2 2 1 4 3 3 4 2 1 I would like to be able to create an array with equal numbers of rows (24) for each column, i.e., fill in the gaps with Zeros. [[5]] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 0 2 0 0 1 1 0 2 1 5 3 6 6 3 2 2 1 4 3 0 3 4 2 1 Any suggestions? thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch 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] List 'sssitalk' closed to public posts
Sorry, but your posting is being returned to you. The list is temporarily restricted. If your post is substantive, dealing with SSSI issues, it will be forwarded to the list. If it is intended as private email, it will be forwarded accordingly. If you wish to subscribe to SSSITALK, send a message that says: subscribe sssitalk firstname lastname (firstname/lastname are YOUR first and last name) If you have questions about SSSI, see: http://www.soci.niu.edu/~sssi If you have questions, contact: Jim Thomas at: [EMAIL PROTECTED] --- Listar v1.0.0 - job execution complete. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] list of interdependent functions
Hello, I discussed the following problem on the great useR conference with several people and wonder if someone of you knows a more elegant (or more common ?) solution than the one below. The problem: I have several sets of interrelated functions which should be compared. The functions themselves have different structure, application-specific names (for readability) and they should be exchangeable. I want to avoid to construct a generic for every new function, but the functions should be aggregated together in a common data structure (e.g. list eq or an S4 instance) *and* it should be able for them to see and call each other with too many $ or @. These functions are used in another function (called solver here) which may be used to prepare something before the call to f2. The example and a possible solution (which uses an environment manipulating function putInEnv()) is given below. Thanks a lot Thomas ##== ## An example ##== ## a small list of functions eq - list( f1 = function(x, K) K - x, f2 = function(x, r, K) r * x * f1(x, K) ) ## a solver fnction which calls them solverB - function(eq) { eq - putInEnv(eq, environment()) # that's the trick f1(3,4) + f2(1,2,3) } ## and the final call (e.g. from the command line) solverB(eq) ##== ## One possible solution. Is there a better one??? ##== putInEnv - function(eq, e) { ## clone, very important to avoid interferences!!! eq - as.list(unlist(eq)) lapply(eq, environment-, e) nn - names(eq) for (i in 1:length(eq)) { assign(nn[i], eq[[i]], envir = e) } eq } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list of interdependent functions
Martin Morgan wrote: Here's another way: makeSolver - function() { f1 - function(x, K) K - x f2 - function(x, r, K) r * x * f1(x, K) function() f1(3,4) + f2(1,2,3) } solverB - makeSolver() solverB() makeSolver (implicitly) creates an environment, installs f1 and f2 into it, and then returns a function that gets assigned to solverB. Calling solverB invokes the function in makeSolver, so f1 and f2 are visible to it. The principle is similar to the 'bank account' example in section 10.7 of 'An introduction to R', available in the manuals section of cran. Thank you, and of course, I know this section, but's in fact a little bit different and uses a list of functions inside a function. Your solution is obvious at a first look but more tricky in the details. I wonder if it is possible to access the functions directly, e.g. to change the body of f1 from K-x to, say 1 (switch it off) or to introduce new functions afterwards (in a straigtforward way avoiding things like as.list(body) ... A down side is that the signature of solverB is not obvious; I'm not sure how the documentation facilities (R CMD check) cope with this. I don't know either and it may seem a little bit ghostly (to some users ;-) that one copies R function makeSolver to solverB but in reality gets a completely different function solverB that in fact uses *delegation* to access functions f1 and f2 stored in another object. Nice poster at useR! Thanks! Martin Thank you again. Thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] List to Array
Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
probably you're looking for either do.call(rbind, lis) or do.call(cbind, lis) where 'lis' is your list. I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Werner Wernersen [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Wednesday, April 05, 2006 2:55 PM Subject: [R] List to Array Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
Please supply some test data and the expected answer since its not clear what is desired here. On 4/5/06, Werner Wernersen [EMAIL PROTECTED] wrote: Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
Werner Wernersen pensterfuzzer at yahoo.de writes: Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? I think if you really mean array (i.e. an n-dimensional table with n2) then something like the following will do it: ## create an example list of matrices z - replicate(5,matrix(runif(9),nrow=3),simplify=FALSE) library(abind) do.call(abind,c(z,list(along=3))) Ben Bolker __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
On 4/5/06, Ben Bolker [EMAIL PROTECTED] wrote: Werner Wernersen pensterfuzzer at yahoo.de writes: Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? I think if you really mean array (i.e. an n-dimensional table with n2) then something like the following will do it: ## create an example list of matrices z - replicate(5,matrix(runif(9),nrow=3),simplify=FALSE) library(abind) do.call(abind,c(z,list(along=3))) Note that if that is what he is looking for then abind(z, along = 3) will do it too. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
Oh yes, I should give an example: m - matrix(1:6,nrow=3) L - list(m,m) Output of L: [[1]] [,1] [,2] [1,]14 [2,]25 [3,]36 [[2]] [,1] [,2] [1,]14 [2,]25 [3,]36 I would like to transform L to and array looking like this: , , 1 [,1] [,2] [1,]14 [2,]25 [3,]36 , , 2 [,1] [,2] [1,]14 [2,]25 [3,]36 Please supply some test data and the expected answer since its not clear what is desired here. On 4/5/06, Werner Wernersen [EMAIL PROTECTED] wrote: Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
then maybe this is what you're looking for: L - list(matrix(rnorm(6), nrow = 3), matrix(rnorm(6), nrow = 3)) L array(unlist(L), dim = c(nrow(L[[1]]), ncol(L[[1]]), length(L))) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Werner Wernersen [EMAIL PROTECTED] To: Gabor Grothendieck [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Wednesday, April 05, 2006 3:55 PM Subject: Re: [R] List to Array Oh yes, I should give an example: m - matrix(1:6,nrow=3) L - list(m,m) Output of L: [[1]] [,1] [,2] [1,]14 [2,]25 [3,]36 [[2]] [,1] [,2] [1,]14 [2,]25 [3,]36 I would like to transform L to and array looking like this: , , 1 [,1] [,2] [1,]14 [2,]25 [3,]36 , , 2 [,1] [,2] [1,]14 [2,]25 [3,]36 Please supply some test data and the expected answer since its not clear what is desired here. On 4/5/06, Werner Wernersen [EMAIL PROTECTED] wrote: Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
Which can be written: array(unlist(L), dim = c(dim(L[[1]]), length(L))) On 4/5/06, Dimitris Rizopoulos [EMAIL PROTECTED] wrote: then maybe this is what you're looking for: L - list(matrix(rnorm(6), nrow = 3), matrix(rnorm(6), nrow = 3)) L array(unlist(L), dim = c(nrow(L[[1]]), ncol(L[[1]]), length(L))) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Werner Wernersen [EMAIL PROTECTED] To: Gabor Grothendieck [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Wednesday, April 05, 2006 3:55 PM Subject: Re: [R] List to Array Oh yes, I should give an example: m - matrix(1:6,nrow=3) L - list(m,m) Output of L: [[1]] [,1] [,2] [1,]14 [2,]25 [3,]36 [[2]] [,1] [,2] [1,]14 [2,]25 [3,]36 I would like to transform L to and array looking like this: , , 1 [,1] [,2] [1,]14 [2,]25 [3,]36 , , 2 [,1] [,2] [1,]14 [2,]25 [3,]36 Please supply some test data and the expected answer since its not clear what is desired here. On 4/5/06, Werner Wernersen [EMAIL PROTECTED] wrote: Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List to Array
That's great, thanks a lot! :) Which can be written: array(unlist(L), dim = c(dim(L[[1]]), length(L))) On 4/5/06, Dimitris Rizopoulos [EMAIL PROTECTED] wrote: then maybe this is what you're looking for: L - list(matrix(rnorm(6), nrow = 3), matrix(rnorm(6), nrow = 3)) L array(unlist(L), dim = c(nrow(L[[1]]), ncol(L[[1]]), length(L))) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Werner Wernersen [EMAIL PROTECTED] To: Gabor Grothendieck [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Wednesday, April 05, 2006 3:55 PM Subject: Re: [R] List to Array Oh yes, I should give an example: m - matrix(1:6,nrow=3) L - list(m,m) Output of L: [[1]] [,1] [,2] [1,]14 [2,]25 [3,]36 [[2]] [,1] [,2] [1,]14 [2,]25 [3,]36 I would like to transform L to and array looking like this: , , 1 [,1] [,2] [1,]14 [2,]25 [3,]36 , , 2 [,1] [,2] [1,]14 [2,]25 [3,]36 Please supply some test data and the expected answer since its not clear what is desired here. On 4/5/06, Werner Wernersen [EMAIL PROTECTED] wrote: Hi, this is probably the easiest thing to do but I manage not finding the answer: I have a list with matrices of exact same format and headers. Now I would like to transform the list into an normal array. What is the proper way to do this? as.array changes the entire format and right now I only found the method of creating a new array, going through the entire list and copy the matrix in each list element to the new array. Thanks a million for your help! Werner __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] List Conversion
Hello, I have a list (mode and class are list) in R that is many elements long and of the form: length(list) [1] 5778 list[1:4] $ID1 [1] num1 $ID2 [1] num2 num3 $ID3 [1] num4 $ID4 [1] NA I'd like to convert the $ID2 value to be in one element rather than in two. It shows up as c(\num2\, \num3\) if I try to use paste(list[2], collapse=). I need to do this over the length of the entire list, however list2 - apply(list, 1, paste, collapse=) tells me 'Error in apply : dim(X) must have a positive length'. dim(list) does not have a positive length, which I think is due to the fact that it's a list and not a matrix or data frame. What I want to get is: list[1:4] $ID1 [1] num1 $ID2 [1] num2 num3 $ID3 [1] num4 $ID4 [1] NA Thanks. Liz -- ___ Play 100s of games for FREE! http://games.mail.com/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List Conversion
LD == Liz Dem [EMAIL PROTECTED] writes: LD I have a list (mode and class are list) in R that is many elements long and of the form: length(list) LD [1] 5778 list[1:4] LD $ID1 LD [1] num1 LD $ID2 LD [1] num2 num3 LD $ID3 LD [1] num4 LD $ID4 LD [1] NA LD I'd like to convert the $ID2 value to be in one element rather LD than in two. It shows up as c(\num2\, \num3\) if I try to LD use paste(list[2], collapse=). You want list[[2]], not list[2]: tt - list(ID1=num1, ID2=c(num2, num3), ID3 = num4, ID4 =NA) tt $ID1 [1] num1 $ID2 [1] num2 num3 $ID3 [1] num4 $ID4 [1] NA paste(tt[2], collapse=) [1] c(\num2\, \num3\) paste(tt[[2]], collapse=) [1] num2num3 paste(tt[[2]], collapse= ) [1] num2 num3 LD I need to do this over the length of the entire list, however LD list2 - apply(list, 1, paste, collapse=) tells me 'Error in LD apply : dim(X) must have a positive length'. You want to use `lapply' not `apply': tt1 - lapply(tt, paste, collapse= ) tt1 $ID1 [1] num1 $ID2 [1] num2 num3 $ID3 [1] num4 $ID4 [1] NA LD What I want to get is: list[1:4] LD $ID1 LD [1] num1 LD $ID2 LD [1] num2 num3 LD $ID3 LD [1] num4 LD $ID4 LD [1] NA In that case, if you don't want NA's to turn into strings: tt2 - lapply(tt, function(x) if(is.na(x[1])) NA else paste(x, collapse= )) tt2 $ID1 [1] num1 $ID2 [1] num2 num3 $ID3 [1] num4 $ID4 [1] NA HTH. Cheers, Berwin == Full address Berwin A Turlach Tel.: +61 (8) 6488 3338 (secr) School of Mathematics and Statistics+61 (8) 6488 3383 (self) The University of Western Australia FAX : +61 (8) 6488 1028 35 Stirling Highway Crawley WA 6009e-mail: [EMAIL PROTECTED] Australiahttp://www.maths.uwa.edu.au/~berwin __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List of lists???
Thx for the hint... the div - factor(c(1,1,1,2,2)) did exactly what I was expecting... Stéphane. Le Mardi 31 Janvier 2006 15:50, Gabor Grothendieck a écrit : Your post seems to be messed up but I will assume you have a 5 column data frame and the questino is how to run f on the first three columns and separately on the last two. I think the easiest is just the following where I have used the builtin iris data set where I have assumed that the operation you want to perform is summary for purposes of example: summary(iris[,1:3]) summary(iris[,4:5]) If this is not your real problem and the real problem has many more divisions then try this where div is a factor that defines the division of columns into sets: div - factor(c(1,1,1,2,2)) lapply(split(names(iris), div), function(n) summary(iris[n])) On 1/31/06, Stephane CRUVEILLER [EMAIL PROTECTED] wrote: Hi, I would like to perform computations on some variables belonging to the same dataframe. For instance my data frame has the following shape: toto1toto2toto3toto4toto5 1 12345 2678910 I would like to perform the calculation on c(toto1,toto2,toto3) and then the same calculation on c(toto4,toto5). Is there a way to tell R to do it using 3 loop (a list of lists)?? Stephane. -- == Stephane CRUVEILLER Ph. D. Genoscope - Centre National de Sequencage Atelier de Genomique Comparative 2, Rue Gaston Cremieux CP 5706 91057 Evry Cedex - France Phone: +33 (0)1 60 87 84 58 Fax: +33 (0)1 60 87 25 14 EMails: [EMAIL PROTECTED] ,[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- == Stephane CRUVEILLER Ph. D. Genoscope - Centre National de Sequencage Atelier de Genomique Comparative 2, Rue Gaston Cremieux CP 5706 91057 Evry Cedex - France Phone: +33 (0)1 60 87 84 58 Fax: +33 (0)1 60 87 25 14 EMails: [EMAIL PROTECTED] ,[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] List of lists???
Hi, I would like to perform computations on some variables belonging to the same dataframe. For instance my data frame has the following shape: toto1 toto2 toto3 toto4 toto5 1 1 2 3 4 5 2 6 7 8 9 10 I would like to perform the calculation on c(toto1,toto2,toto3) and then the same calculation on c(toto4,toto5). Is there a way to tell R to do it using a loop (a list of lists)?? Stephane. -- == Stephane CRUVEILLER Ph. D. Genoscope - Centre National de Sequencage Atelier de Genomique Comparative 2, Rue Gaston Cremieux CP 5706 91057 Evry Cedex - France Phone: +33 (0)1 60 87 84 58 Fax: +33 (0)1 60 87 25 14 EMails: [EMAIL PROTECTED] ,[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List of lists???
Your post seems to be messed up but I will assume you have a 5 column data frame and the questino is how to run f on the first three columns and separately on the last two. I think the easiest is just the following where I have used the builtin iris data set where I have assumed that the operation you want to perform is summary for purposes of example: summary(iris[,1:3]) summary(iris[,4:5]) If this is not your real problem and the real problem has many more divisions then try this where div is a factor that defines the division of columns into sets: div - factor(c(1,1,1,2,2)) lapply(split(names(iris), div), function(n) summary(iris[n])) On 1/31/06, Stephane CRUVEILLER [EMAIL PROTECTED] wrote: Hi, I would like to perform computations on some variables belonging to the same dataframe. For instance my data frame has the following shape: toto1toto2toto3toto4toto5 1 12345 2678910 I would like to perform the calculation on c(toto1,toto2,toto3) and then the same calculation on c(toto4,toto5). Is there a way to tell R to do it using 3 loop (a list of lists)?? Stephane. -- == Stephane CRUVEILLER Ph. D. Genoscope - Centre National de Sequencage Atelier de Genomique Comparative 2, Rue Gaston Cremieux CP 5706 91057 Evry Cedex - France Phone: +33 (0)1 60 87 84 58 Fax: +33 (0)1 60 87 25 14 EMails: [EMAIL PROTECTED] ,[EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list entries file into a list
This worked great but I'm a bit confused about how to access the names (keys?) of a list in a loop, and why this is failing for me: I want to cross the entries in mylist (like entry0001) with the columns of a dataframe ginput: $entry0001 [1] AB0032 CF32134 DF34334 $entry0002 [1] AB0033 $entry0003 [1] AB0032 CF32134 DF34334 DD343434 DD34222 $entry0004 [1] AB0032 CF32134 ginput midreffile pa 1 myetag0001 AB0032 0.778270 2 myetag0002 AB0032 0.153093 3 myetag0003 AB0032 0.392175 4 myetag0004 AB0032 0.696303 5 myetag0005 AB0032 0.688537 6 myetag0006 AB0032 0.767044 7 myetag0001 AB0033 0.42 8 myetag0002 AB0033 0.330333 9 myetag0003 AB0033 0.238013 10myetag0004 AB0033 0.043213 ... The rough idea has been to do something like: mynames = rep(0,length(names(mylist))) mypas = rep(0,length(names(mylist))) i = 0 for (entrylabel in names(mylist)) { mynames[i] = entrylabel mypas[i] =+ sum(ginput$pa[ginput$reffile %in% mylist$entrylabel]) i = i+1 } But mylist$entrylabel is not working inside the loop. I checked that entrylabel returns: [1] entry0001 And that mylist$entry0001 is returning the right list. I would like to end up with something like: dfpa = data.frame(dfnames=mynames,dfpas=mypas) dfpa dfnames dfpas 1 entry00013.475422 2 entry00022.221355 ... I haven't been able to found my way with R lists, maybe because I'm comparing them with perl's hashes. Any idea of what I'm missing? Albert. El dj 26 de 01 del 2006 a les 08:14 -0500, en/na Liaw, Andy va escriure: The following might be what you want (replace clipboard with your filename): mylist - strsplit(readLines(clipboard), :) nm - sapply(mylist, [, 1) mylist - lapply(mylist, [, -1) names(mylist) - nm mylist - lapply(mylist, function(s) strsplit(s, ,)[[1]]) mylist $entry0001 [1] AB0032 CF32134 DF34334 $entry0002 [1] AB0033 $entry0003 [1] AB0032 CF32134 DF34334 DD343434 DD34222 $entry0004 [1] AB0032 CF32134 Andy From: Albert Vilella Hi all, I have a file of this kind: entry0001:AB0032,CF32134,DF34334 entry0002:AB0033 entry0003:AB0032,CF32134,DF34334,DD343434,DD34222 entry0004:AB0032,CF32134 And I would like to read it into something like a hash, so that I can then loop over it by keys and values. I wonder which would be the best way to do that in R? Thanks, Albert. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Notice: This e-mail message, together with any attachment...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list entries file into a list
On 27 Jan 2006, [EMAIL PROTECTED] wrote: But mylist$entrylabel is not working inside the loop. '$' doesn't evaluate its argument. You want mylist[[entrylabel]]. I haven't been able to found my way with R lists, maybe because I'm comparing them with perl's hashes. R lists do have names, but they are not hashes. You can have duplicate names in different positions in a list. You can get at list elements by name using $name and [[name]], but the argument to $ has to be the actual name, not a var containing the name. You can also access elements by number using [[i]] HTH, + seth __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] list entries file into a list
Hi all, I have a file of this kind: entry0001:AB0032,CF32134,DF34334 entry0002:AB0033 entry0003:AB0032,CF32134,DF34334,DD343434,DD34222 entry0004:AB0032,CF32134 And I would like to read it into something like a hash, so that I can then loop over it by keys and values. I wonder which would be the best way to do that in R? Thanks, Albert. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list entries file into a list
The following might be what you want (replace clipboard with your filename): mylist - strsplit(readLines(clipboard), :) nm - sapply(mylist, [, 1) mylist - lapply(mylist, [, -1) names(mylist) - nm mylist - lapply(mylist, function(s) strsplit(s, ,)[[1]]) mylist $entry0001 [1] AB0032 CF32134 DF34334 $entry0002 [1] AB0033 $entry0003 [1] AB0032 CF32134 DF34334 DD343434 DD34222 $entry0004 [1] AB0032 CF32134 Andy From: Albert Vilella Hi all, I have a file of this kind: entry0001:AB0032,CF32134,DF34334 entry0002:AB0033 entry0003:AB0032,CF32134,DF34334,DD343434,DD34222 entry0004:AB0032,CF32134 And I would like to read it into something like a hash, so that I can then loop over it by keys and values. I wonder which would be the best way to do that in R? Thanks, Albert. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List Email Statistic
This also depends on which field you are interested in, for example MEDSTATS (http://tinyurl.com/bwha8) ED-STATS (http://lists.psu.edu/archives/edstat-l.html) and a few more http://tinyurl.com/a8wo4 Regards, Adai On Fri, 2005-09-30 at 07:32 -0500, Marc Schwartz wrote: On Thu, 2005-09-29 at 23:47 -0500, José Raul Capablanca wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. If you have access to Usenet either via an NNTP server or via Google Groups, there are three principal groups for general statistics discussion: sci.stat.consult (http://groups.google.com/group/sci.stat.consult) sci.stat.math(http://groups.google.com/group/sci.stat.math) sci.stat.edu (http://groups.google.com/group/sci.stat.edu) There is a greater level of volume on the first two for general discussion. sci.stat.edu (which is targeted more to statistics education discussion) has been split off as a gateway to the edstat-L list, which has substantively reduced its daily volume. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List Email Statistic
Indeed. I was not aware of the additional non-usenet statistics Google Groups. Some familiar names on the MEDSTATS list... :-) Thanks Adai. Marc On Sat, 2005-10-01 at 18:17 +0100, Adaikalavan Ramasamy wrote: This also depends on which field you are interested in, for example MEDSTATS (http://tinyurl.com/bwha8) ED-STATS (http://lists.psu.edu/archives/edstat-l.html) and a few more http://tinyurl.com/a8wo4 Regards, Adai On Fri, 2005-09-30 at 07:32 -0500, Marc Schwartz wrote: On Thu, 2005-09-29 at 23:47 -0500, José Raul Capablanca wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. If you have access to Usenet either via an NNTP server or via Google Groups, there are three principal groups for general statistics discussion: sci.stat.consult (http://groups.google.com/group/sci.stat.consult) sci.stat.math(http://groups.google.com/group/sci.stat.math) sci.stat.edu (http://groups.google.com/group/sci.stat.edu) There is a greater level of volume on the first two for general discussion. sci.stat.edu (which is targeted more to statistics education discussion) has been split off as a gateway to the edstat-L list, which has substantively reduced its daily volume. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] List Email Statistic
Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. __ Espacio para todos tus mensajes, antivirus y antispam ¡gratis! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List Email Statistic
There is some discussion and data sources of the volume of email on the list in: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/27532.html On 9/30/05, José Raul Capablanca [EMAIL PROTECTED] wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. __ Espacio para todos tus mensajes, antivirus y antispam ¡gratis! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List Email Statistic
José Raul Capablanca wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. Hola Jose, If you mean a list devoted exclusively to statistics (Si desea una lista solo para la statistica) http://www.jiscmail.ac.uk/lists/allstat.html (y una lista econometria en espanol) http://www.rediris.es/list/info/econometria.html Jim __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List Email Statistic
On 30-Sep-05 Jim Lemon wrote: José Raul Capablanca wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. Hola Jose, If you mean a list devoted exclusively to statistics (Si desea una lista solo para la statistica) http://www.jiscmail.ac.uk/lists/allstat.html I should point out that the 'allstat' list is, by policy, NOT a discussion list (as many have found out!). It is primarily a list for announcements etc. People do post queries, but replies are not supposed to be sent to the list thought they are often summarised to the list by the person making the original query. Anything that looks as though it will develop into an on-list discussion will be brought to a halt by the list administrator. There is a good statistics discussion list STAT-L. See: http://lists.mcgill.ca/archives/stat-l.html where you can sample the archives and find pointers to the admin pages (for subscribing etc.). However, it has a low activity rate. I think R-help also serves as a general statistics discussion list which is as good as anything else I have come across! There are of course many statistics lists for special areas of application or particular methodology or particular software. With best wishes, Ted. [Or should I sign as Emmanuel Lasker?] E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 30-Sep-05 Time: 10:03:51 -- XFMail -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List Email Statistic
On Thu, 2005-09-29 at 23:47 -0500, José Raul Capablanca wrote: Dear All, How can I can to know a mail list , to speak about exclusively statistic. Thanks. If you have access to Usenet either via an NNTP server or via Google Groups, there are three principal groups for general statistics discussion: sci.stat.consult (http://groups.google.com/group/sci.stat.consult) sci.stat.math(http://groups.google.com/group/sci.stat.math) sci.stat.edu (http://groups.google.com/group/sci.stat.edu) There is a greater level of volume on the first two for general discussion. sci.stat.edu (which is targeted more to statistics education discussion) has been split off as a gateway to the edstat-L list, which has substantively reduced its daily volume. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] List and Column Names in a Function?
In this simple function, how can I pass strings for index and column names to the function? I've posted this type of question before and received no response. Maybe this example will be easier to understand and troubleshoot. ds - function(myds, vec) {myds[[vec]]*2} ds1 - c(X=list(1:10), Y=list(11:20)) ds(get(ds1),get(Y)) [EMAIL PROTECTED] Kenneth Ray Hobson, P.E. Oklahoma DOT - QA IAS Manager Oklahoma City, OK 73105-3204 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] List and Column Names in a Function?
[EMAIL PROTECTED] wrote: In this simple function, how can I pass strings for index and column names to the function? I've posted this type of question before and received no response. Maybe this example will be easier to understand and troubleshoot. ds - function(myds, vec) {myds[[vec]]*2} ds1 - c(X=list(1:10), Y=list(11:20)) ds(get(ds1),get(Y)) You are overusing the get function. I think you can do what you want as ds(ds1, Y) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] List of tables rather than an extra dimension in the table or (l)apply(xtabs)
I'm not sure how to best explain what I am after but here goes. I have a data frame with 2 geographical factors. One is the major region the other is the component regions. I am trying to process all the regions at the same time without using for. So I need (think, I do) a list of matrices each structured according to the number of subregions within each region. So is there a way of using lapply with xtabs or is there a better way to achieve my desired output? Using the Titanic data as an example t1 - as.data.frame(Titanic) t2 - split(t1,t1$Class) # I would then drop any unused levels in the factors for the geography creating distinctly different data.frames (see end of message) xtabs(Freq ~ Age + Sex + Class,t1) , , Class = 1st Sex Age Male Female Child 51 Adult 175 144 , , Class = 2nd Sex Age Male Female Child 11 13 Adult 168 93 , , Class = 3rd Sex Age Male Female Child 48 31 Adult 462 165 , , Class = Crew Sex Age Male Female Child 00 Adult 862 23 Can I do something with t2 to produce a list which is in effect an Age by Sex crosstab with one item for each value of Class. I would be wanting to drop.unused.levels, so that the last part of the table is just Sex Age Male Female Adult 862 23 or in my case each item in the list has the same number of rows as there are subregions for that region. List of 9 $ 1:`data.frame': 4009 obs. of 7 variables: ..$ sex : Factor w/ 2 levels Females,Males: 2 2 2 2 2 2 2 2 2 2 ... ..$ age : Factor w/ 18 levels 0-4,5-9,10-14,..: 1 1 1 1 1 1 1 1 1 1 ... ..$ lga : Factor w/ 23 levels Carnamah (S),..: 1 2 3 4 5 6 7 8 9 10 ... # 23 subregions ..$ psn : num [1:4009] 71 336 26 84 30 133 904 385 99 110 ... ..$ year : num [1:4009] 1991 1991 1991 1991 1991 ... ..$ agecomp : Factor w/ 14 levels 0-4,5-9,10-14,..: 1 1 1 1 1 1 1 1 1 1 ... ..$ RegionNum: num [1:4009] 1 1 1 1 1 1 1 1 1 1 ... $ 2:`data.frame': 720 obs. of 7 variables: ..$ sex : Factor w/ 2 levels Females,Males: 2 2 2 2 2 2 2 2 2 2 ... ..$ age : Factor w/ 18 levels 0-4,5-9,10-14,..: 1 1 1 1 2 2 2 2 3 3 ... ..$ lga : Factor w/ 4 levels Broome (S),De..,..: 1 2 3 4 1 2 3 4 1 2 ... # 4 subregions etc ..$ psn : num [1:720] 495 445 189 377 415 374 189 330 324 319 ... ..$ year : num [1:720] 1991 1991 1991 1991 1991 ... ..$ agecomp : Factor w/ 14 levels 0-4,5-9,10-14,..: 1 1 1 1 2 2 2 2 3 3 ... ..$ RegionNum: num [1:720] 2 2 2 2 2 2 2 2 2 2 ... So these two items would produce round(xtabs(psn ~ lga + agecomp,eas[[1]]),-2) agecomp lga 0-4 5-9 10-14 15-19 20-24 25-29 30-34 35-39 40-44 45-49 50-54 55-59 60-64 65plus Carnamah (S) 500 400 300 200 300 300 500 400 400 300 300 200 100 300 Carnarvon (S) 2800 3000 2600 2100 2400 2700 2800 2600 2400 2200 2000 1600 1300 2800 Chapman Valley (S) 300 400 300 200 200 300 300 300 300 400 400 300 200 300 Coorow (S) 700 700 600 200 300 600 700 600 500 500 400 400 300 500 Cue (S) 200 200 100 100 200 200 300 200 200 200 200 100 100 100 Exmouth (S) 900 1000 800 600 700 1100 1100 1100 1100 800 700 500 400 700 Geraldton (C) 7700 7700 8100 8200 7200 7400 7500 7200 6900 6100 5400 4600 4300 12400 Greenough (S) 4700 5400 5500 4400 3100 3700 4800 5100 5200 4200 3500 2600 1900 3200 Irwin (S) 1000 1100 1000 600 600 900 1000 1200 1000 900 800 900 800 1800 Meekatharra (S) 800 700 600 600 900 1000 900 700 600 500 400 300 200 400 Mingenew (S) 300 300 200 100 200 200 300 300 200 200 200 200 100 200 Morawa (S) 400 500 400 400 200 400 500 400 300 300 300 300 200 500 Mount Magnet (S) 500 400 300 200 400 500 400 400 300 300 200 200 100 200 Mullewa (S) 600 600 800 400 400 500 500 400 300 300 300 300 200 400 Murchison (S)100 100 100 100 0 100 100 0 0 0 100 0 0 0 Northampton (S) 1300 1300 1200 700 700 900 1200 1300 1200 1200 1000 1000 900 2000 Perenjori (S)300 300 300 100 200 200 300 300 300 200 200 200 100 300 Sandstone (S) 0 0 0 0 100 100 100 100 100 100 100 100 0 100 Shark Bay (S)300 300 200 200 200 300 400 400 400 300 300 300 200 600 Three Springs (S)300 300 300 100 200 300 400 300 300 200 300 200 200 400 Upper Gascoyne (S) 100
RE: [R] List of tables rather than an extra dimension in the table or (l)apply(xtabs)
I wrote a function that created the crosstab and removed the extraneous lines and then used lapply aestabs - function(x){ temp - xtabs(psn ~ lga + year,x) temp - temp[rowSums(temp) != 0,] return(temp) } eas2 - lapply(split(ipi$eas,ipi$eas$RegionNum),aestabs) It's not really reuseable. I guess I could pass a formula and work out a better method of subsetting dimensions (where certain factor levels are not used. But maybe someone has an elegant method they could share. Tom -Original Message- From: Mulholland, Tom Sent: Tuesday, 22 March 2005 1:35 PM To: R-Help (E-mail) Subject: [R] List of tables rather than an extra dimension in the table or (l)apply(xtabs) I'm not sure how to best explain what I am after but here goes. I have a data frame with 2 geographical factors. One is the major region the other is the component regions. I am trying to process all the regions at the same time without using for. So I need (think, I do) a list of matrices each structured according to the number of subregions within each region. So is there a way of using lapply with xtabs or is there a better way to achieve my desired output? Using the Titanic data as an example t1 - as.data.frame(Titanic) t2 - split(t1,t1$Class) # I would then drop any unused levels in the factors for the geography creating distinctly different data.frames (see end of message) xtabs(Freq ~ Age + Sex + Class,t1) , , Class = 1st Sex Age Male Female Child 51 Adult 175 144 , , Class = 2nd Sex Age Male Female Child 11 13 Adult 168 93 , , Class = 3rd Sex Age Male Female Child 48 31 Adult 462 165 , , Class = Crew Sex Age Male Female Child 00 Adult 862 23 Can I do something with t2 to produce a list which is in effect an Age by Sex crosstab with one item for each value of Class. I would be wanting to drop.unused.levels, so that the last part of the table is just Sex Age Male Female Adult 862 23 or in my case each item in the list has the same number of rows as there are subregions for that region. List of 9 $ 1:`data.frame': 4009 obs. of 7 variables: ..$ sex : Factor w/ 2 levels Females,Males: 2 2 2 2 2 2 2 2 2 2 ... ..$ age : Factor w/ 18 levels 0-4,5-9,10-14,..: 1 1 1 1 1 1 1 1 1 1 ... ..$ lga : Factor w/ 23 levels Carnamah (S),..: 1 2 3 4 5 6 7 8 9 10 ... # 23 subregions ..$ psn : num [1:4009] 71 336 26 84 30 133 904 385 99 110 ... ..$ year : num [1:4009] 1991 1991 1991 1991 1991 ... ..$ agecomp : Factor w/ 14 levels 0-4,5-9,10-14,..: 1 1 1 1 1 1 1 1 1 1 ... ..$ RegionNum: num [1:4009] 1 1 1 1 1 1 1 1 1 1 ... $ 2:`data.frame': 720 obs. of 7 variables: ..$ sex : Factor w/ 2 levels Females,Males: 2 2 2 2 2 2 2 2 2 2 ... ..$ age : Factor w/ 18 levels 0-4,5-9,10-14,..: 1 1 1 1 2 2 2 2 3 3 ... ..$ lga : Factor w/ 4 levels Broome (S),De..,..: 1 2 3 4 1 2 3 4 1 2 ... # 4 subregions etc ..$ psn : num [1:720] 495 445 189 377 415 374 189 330 324 319 ... ..$ year : num [1:720] 1991 1991 1991 1991 1991 ... ..$ agecomp : Factor w/ 14 levels 0-4,5-9,10-14,..: 1 1 1 1 2 2 2 2 3 3 ... ..$ RegionNum: num [1:720] 2 2 2 2 2 2 2 2 2 2 ... So these two items would produce round(xtabs(psn ~ lga + agecomp,eas[[1]]),-2) agecomp lga 0-4 5-9 10-14 15-19 20-24 25-29 30-34 35-39 40-44 45-49 50-54 55-59 60-64 65plus Carnamah (S) 500 400 300 200 300 300 500 400 400 300 300 200 100 300 Carnarvon (S) 2800 3000 2600 2100 2400 2700 2800 2600 2400 2200 2000 1600 1300 2800 Chapman Valley (S) 300 400 300 200 200 300 300 300 300 400 400 300 200 300 Coorow (S) 700 700 600 200 300 600 700 600 500 500 400 400 300 500 Cue (S) 200 200 100 100 200 200 300 200 200 200 200 100 100 100 Exmouth (S) 900 1000 800 600 700 1100 1100 1100 1100 800 700 500 400 700 Geraldton (C) 7700 7700 8100 8200 7200 7400 7500 7200 6900 6100 5400 4600 4300 12400 Greenough (S) 4700 5400 5500 4400 3100 3700 4800 5100 5200 4200 3500 2600 1900 3200 Irwin (S) 1000 1100 1000 600 600 900 1000 1200 1000 900 800 900 800 1800 Meekatharra (S) 800 700 600 600 900 1000 900 700 600 500 400 300 200 400 Mingenew (S) 300 300 200 100 200 200 300 300 200 200 200 200 100 200 Morawa (S) 400 500 400 400 200 400 500 400 300 300 300 300 200 500 Mount Magnet (S) 500 400 300 200
Re: [R] R: LIST function and LOOPS
Clark Allan wrote: hi thanx for the help. i dont want to use matrices. i solve my problem, see the example below. the set.seed is used because in my actual application i need to generate INDEPENDENT variables. will this ensure that the variables are independent? Why do you want to set.seed() inside the loop? Just set it once at the beginning of your simulation in order to get reproducible results - you can assume independence anyway. Or maybe I am missing the point why you are going to set.seed() inside the loop. Uwe Ligges z3-function(w) { for (i in 1:w) { ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r a-list(ss=ss,r=r) } print(paste( i=,i,)) print(a) } } z3(3) z3(3) [1] i= 1 $ss [1] -2.213343 $r [1] 0.269606 [1] i= 2 $ss [1] -2.904235 $r [1] -1.480568 [1] i= 3 $ss [1] -0.01516304 $r [1] 0.9264592 thanx again *** allan ### ### ### ### ### ### Adaikalavan Ramasamy wrote: You will need to capture the value of ss at the end of each 'i' as such z4 -function(w){ output - numeric(w) for (i in 1:w){ set.seed(i+6) # this is redundant line ss-0 for (j in 1:5){ set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } output[i] - ss } return(output) } BTW, I do not think it is a good idea to set.seed() so many times. To answer you more general question, see if the following is useful. I am trying to simulate 'n' values from a standard normal distribution but 'n' is random variable itself. f -function(w, lambda=3){ tmp - list(NULL) for (i in 1:w){ n - 1 + rpois(1, lambda=lambda) # number of simulation required tmp[[ i ]] - rnorm(n) } # flatten the list into a ragged matrix out.lengths - sapply(tmp, length) out - matrix( nr=w, nc=max( out.lengths ) ) rownames(out) - paste(w =, 1:w) for(i in 1:w) out[i, 1:out.lengths[i] ] - tmp[[i]] return(out) } f(6, lambda=3) It is not very elegant but I hope that helps you out somehow. Regards, Adai On Thu, 2005-03-10 at 10:16 +0200, Clark Allan wrote: hi all another simple question. i've written a dummy program so that you get the concept. (the code could be simplfied such that there are no loops. but lets leave the loops in for now.) z1-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } list(ss=ss) } } check.1-z1(3) check.1 the results is: $ss [1] -0.01516304 what i want is something that looks like this: j=1 $ss [1] -2.213343 j=2 $ss [1] -2.904235 j=3 $ss [1] -0.01516304 i know that i could use the print command. (see z2) z2-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } print(ss) } } check.2-z2(3) check.2 check.2-z2(3) [1] -2.213343 [1] -2.904235 [1] -0.01516304 check.2 [1] -0.01516304 the problem with z2 is that only the last value is saved. what i could do is use matrices like the following: (but i dont want to do this AND WOULD PREFER TO USE list.) z3-function(w) { results.-matrix(nrow=w,ncol=1) colnames(results.)-c(ss) for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } results.[i,1]-ss } results. } check.3-z3(3) check.3 check.3 ss [1,] -2.21334260 [2,] -2.90423463 [3,] -0.01516304 what if i have a new program (something different) and i want the following: j=1 $a 1 2 3 $b 1 2 3 4 5 $c 1 ### j=2 $a 11 21 31 $b 11 21 31 41 51 $c 11 ### j=3 $a 21 22 32 $b 21 22 32 42 52 $c 21 MATRICES SEEMS TO BE A GOOD WAY OF DOING THIS (but then you would have to set up three matrices, one for a,b and c). BUT WHAT IF I WANT TO USE THE LIST FUNCTION? i.e. there is a list in the first loop that i want to display! sorry for the long mail. *** ALLAN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch
Re: [R] R: LIST function and LOOPS
hi thanx for the help. i dont want to use matrices. i solve my problem, see the example below. the set.seed is used because in my actual application i need to generate INDEPENDENT variables. will this ensure that the variables are independent? z3-function(w) { for (i in 1:w) { ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r a-list(ss=ss,r=r) } print(paste( i=,i,)) print(a) } } z3(3) z3(3) [1] i= 1 $ss [1] -2.213343 $r [1] 0.269606 [1] i= 2 $ss [1] -2.904235 $r [1] -1.480568 [1] i= 3 $ss [1] -0.01516304 $r [1] 0.9264592 thanx again *** allan ### ### ### ### ### ### Adaikalavan Ramasamy wrote: You will need to capture the value of ss at the end of each 'i' as such z4 -function(w){ output - numeric(w) for (i in 1:w){ set.seed(i+6) # this is redundant line ss-0 for (j in 1:5){ set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } output[i] - ss } return(output) } BTW, I do not think it is a good idea to set.seed() so many times. To answer you more general question, see if the following is useful. I am trying to simulate 'n' values from a standard normal distribution but 'n' is random variable itself. f -function(w, lambda=3){ tmp - list(NULL) for (i in 1:w){ n - 1 + rpois(1, lambda=lambda) # number of simulation required tmp[[ i ]] - rnorm(n) } # flatten the list into a ragged matrix out.lengths - sapply(tmp, length) out - matrix( nr=w, nc=max( out.lengths ) ) rownames(out) - paste(w =, 1:w) for(i in 1:w) out[i, 1:out.lengths[i] ] - tmp[[i]] return(out) } f(6, lambda=3) It is not very elegant but I hope that helps you out somehow. Regards, Adai On Thu, 2005-03-10 at 10:16 +0200, Clark Allan wrote: hi all another simple question. i've written a dummy program so that you get the concept. (the code could be simplfied such that there are no loops. but lets leave the loops in for now.) z1-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } list(ss=ss) } } check.1-z1(3) check.1 the results is: $ss [1] -0.01516304 what i want is something that looks like this: j=1 $ss [1] -2.213343 j=2 $ss [1] -2.904235 j=3 $ss [1] -0.01516304 i know that i could use the print command. (see z2) z2-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } print(ss) } } check.2-z2(3) check.2 check.2-z2(3) [1] -2.213343 [1] -2.904235 [1] -0.01516304 check.2 [1] -0.01516304 the problem with z2 is that only the last value is saved. what i could do is use matrices like the following: (but i dont want to do this AND WOULD PREFER TO USE list.) z3-function(w) { results.-matrix(nrow=w,ncol=1) colnames(results.)-c(ss) for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } results.[i,1]-ss } results. } check.3-z3(3) check.3 check.3 ss [1,] -2.21334260 [2,] -2.90423463 [3,] -0.01516304 what if i have a new program (something different) and i want the following: j=1 $a 1 2 3 $b 1 2 3 4 5 $c 1 ### j=2 $a 11 21 31 $b 11 21 31 41 51 $c 11 ### j=3 $a 21 22 32 $b 21 22 32 42 52 $c 21 MATRICES SEEMS TO BE A GOOD WAY OF DOING THIS (but then you would have to set up three matrices, one for a,b and c). BUT WHAT IF I WANT TO USE THE LIST FUNCTION? i.e. there is a list in the first loop that i want to display! sorry for the long mail. *** ALLAN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting
[R] R: LIST function and LOOPS
hi all another simple question. i've written a dummy program so that you get the concept. (the code could be simplfied such that there are no loops. but lets leave the loops in for now.) z1-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } list(ss=ss) } } check.1-z1(3) check.1 the results is: $ss [1] -0.01516304 what i want is something that looks like this: j=1 $ss [1] -2.213343 j=2 $ss [1] -2.904235 j=3 $ss [1] -0.01516304 i know that i could use the print command. (see z2) z2-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } print(ss) } } check.2-z2(3) check.2 check.2-z2(3) [1] -2.213343 [1] -2.904235 [1] -0.01516304 check.2 [1] -0.01516304 the problem with z2 is that only the last value is saved. what i could do is use matrices like the following: (but i dont want to do this AND WOULD PREFER TO USE list.) z3-function(w) { results.-matrix(nrow=w,ncol=1) colnames(results.)-c(ss) for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } results.[i,1]-ss } results. } check.3-z3(3) check.3 check.3 ss [1,] -2.21334260 [2,] -2.90423463 [3,] -0.01516304 what if i have a new program (something different) and i want the following: j=1 $a 1 2 3 $b 1 2 3 4 5 $c 1 ### j=2 $a 11 21 31 $b 11 21 31 41 51 $c 11 ### j=3 $a 21 22 32 $b 21 22 32 42 52 $c 21 MATRICES SEEMS TO BE A GOOD WAY OF DOING THIS (but then you would have to set up three matrices, one for a,b and c). BUT WHAT IF I WANT TO USE THE LIST FUNCTION? i.e. there is a list in the first loop that i want to display! sorry for the long mail. *** ALLAN__ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] R: LIST function and LOOPS
You will need to capture the value of ss at the end of each 'i' as such z4 -function(w){ output - numeric(w) for (i in 1:w){ set.seed(i+6) # this is redundant line ss-0 for (j in 1:5){ set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } output[i] - ss } return(output) } BTW, I do not think it is a good idea to set.seed() so many times. To answer you more general question, see if the following is useful. I am trying to simulate 'n' values from a standard normal distribution but 'n' is random variable itself. f -function(w, lambda=3){ tmp - list(NULL) for (i in 1:w){ n - 1 + rpois(1, lambda=lambda) # number of simulation required tmp[[ i ]] - rnorm(n) } # flatten the list into a ragged matrix out.lengths - sapply(tmp, length) out - matrix( nr=w, nc=max( out.lengths ) ) rownames(out) - paste(w =, 1:w) for(i in 1:w) out[i, 1:out.lengths[i] ] - tmp[[i]] return(out) } f(6, lambda=3) It is not very elegant but I hope that helps you out somehow. Regards, Adai On Thu, 2005-03-10 at 10:16 +0200, Clark Allan wrote: hi all another simple question. i've written a dummy program so that you get the concept. (the code could be simplfied such that there are no loops. but lets leave the loops in for now.) z1-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } list(ss=ss) } } check.1-z1(3) check.1 the results is: $ss [1] -0.01516304 what i want is something that looks like this: j=1 $ss [1] -2.213343 j=2 $ss [1] -2.904235 j=3 $ss [1] -0.01516304 i know that i could use the print command. (see z2) z2-function(w) { for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } print(ss) } } check.2-z2(3) check.2 check.2-z2(3) [1] -2.213343 [1] -2.904235 [1] -0.01516304 check.2 [1] -0.01516304 the problem with z2 is that only the last value is saved. what i could do is use matrices like the following: (but i dont want to do this AND WOULD PREFER TO USE list.) z3-function(w) { results.-matrix(nrow=w,ncol=1) colnames(results.)-c(ss) for (i in 1:w) { set.seed(i+6) ss-0 for (j in 1:5) { set.seed(j+1+(i-1)*6) r-rnorm(1) ss-ss+r } results.[i,1]-ss } results. } check.3-z3(3) check.3 check.3 ss [1,] -2.21334260 [2,] -2.90423463 [3,] -0.01516304 what if i have a new program (something different) and i want the following: j=1 $a 1 2 3 $b 1 2 3 4 5 $c 1 ### j=2 $a 11 21 31 $b 11 21 31 41 51 $c 11 ### j=3 $a 21 22 32 $b 21 22 32 42 52 $c 21 MATRICES SEEMS TO BE A GOOD WAY OF DOING THIS (but then you would have to set up three matrices, one for a,b and c). BUT WHAT IF I WANT TO USE THE LIST FUNCTION? i.e. there is a list in the first loop that i want to display! sorry for the long mail. *** ALLAN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list(0) to integer
Re-Hello frederic, Don't worry, i have the same english speaking problem, here is what i suggest : n - natScan() natScan - function(){ cat(\n) cat(Give me a natural (everything after the '.' will be ignored)\n) n - scan(, character(), 1,quiet=T) n - as.integer(n) if(length(n)==0||is.na(n)){ cat(!! that's not what i want !!\n) return(natScan()) } return(n) } Hope this helps Frederic renaud a écrit : Because if the user write something else (a real or a character), the program stop. I want in this case (if the user don't write a natural) that the program write again : A natural, please! I've some difficult to speak english! Do you understand? Thanks Fred --- Romain François [EMAIL PROTECTED] wrote: Hello frederic, why don't you just try something like : n - scan(, integer(), 1) You may also need to take a look there : http://zoonek2.free.fr/UNIX/48_R/all.html and maybe there http://addictedtor.free.fr (for the moment there is noting usefull there but soon ) Frederic renaud a écrit : Hello I've another question :-) I would like to transform a list to a integer. I must be sure that the number entered by the user is an integer! Thus, I've made : repeat{ cat(Effectif des populations (integer):) n-scan(,n=1,what=list(0),quiet=TRUE) if (is.integer(n[[1]])==TRUE) break print(L'effectif des population doit etre un entier) } That doesn't work of course but I've no idea to do this. How verify that n[[1]] is an integer an transform them as an integer (as.integer(n) doesn't work!) Someone can help me? Thanks! Fred _ -- Romain FRANCOIS : [EMAIL PROTECTED] page web : http://addictedtor.free.fr/ (en construction) 06 18 39 14 69 / 01 46 80 65 60 ___ Etudiant en 3eme année Institut de Statistique de l'Université de Paris (ISUP) Filière Industrie et Services http://www.isup.cicrp.jussieu.fr/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list(0) to integer
On Mon, 27 Dec 2004 03:18:53 -0800 (PST) Frederic renaud [EMAIL PROTECTED] wrote: Hello I've another question :-) I would like to transform a list to a integer. I must be sure that the number entered by the user is an integer! Thus, I've made : repeat{ cat(Effectif des populations (integer):) n-scan(,n=1,what=list(0),quiet=TRUE) if (is.integer(n[[1]])==TRUE) break print(L'effectif des population doit etre un entier) } if (!is.integer(unlist(n))) stop(L'effectif ...) You don't need `== TRUE' (and I guess you meant `== FALSE') An error action can be executed using stop(some error message). `break' breaks out of the loop (ie goes to the first statement after the loop), so the print statement cannot be executed. Are you sure you need n to be a list ? HTH, Tobias That doesn't work of course but I've no idea to do this. How verify that n[[1]] is an integer an transform them as an integer (as.integer(n) doesn't work!) Someone can help me? Thanks! Fred __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] list of lists question
Hello all, As a general programming question I can't seem to figure out how to make a list of lists in R. As matrices won't work as they have to be rectangular. I am sure that there is an easy solution but... the specific situation is this: - I have created a Tukey confidence interval table and have listed the means that are not significantly different - then using these not significantly different pairs I have created the groups of means that are not significantly different from each other the issue then is that many of these lists are subsets of other lists and I need to check for this. Below is a little program is illustrate the issue a=c(1,1,1,1,1) # generate the first list b=c(2,2,2)# generate a second list c=c(a,b) #combine them cat(c, \n)# and print 1 1 1 1 1 2 2 2 # this is 1-D!!! ahh d=list(a,b)# make a list of a and b d # and print [[1]] #this is exactly what I want, but continue [1] 1 1 1 1 1 [[2]] [1] 2 2 2 e=list(d,a) # now on the next iteration I need to add another list to this list of lists e # and print [[1]] # ahh all hell has broken loose and this is not what I want [[1]][[1]] # desired result below [1] 1 1 1 1 1 [[1]][[2]] [1] 2 2 2 [[2]] [1] 1 1 1 1 1 - desired result #wrong code but this is what I want to happen a=c(1,1,1,1,1,1,1) for(i in 1:5) { a=list(a,1:5) } output I want is (something like) [1] 1 1 1 1 1 1 1 [2] 1 2 3 4 5 [3] 1 2 3 4 5 [4] 1 2 3 4 5 [5] 1 2 3 4 5 [6] 1 2 3 4 5 so then I could call cat(a[1]) and get 1 1 1 1 1 1 1 1 and cat(a[2]) and get 1 2 3 4 5 Anyone know the answer (hopefully simple) Cheers, Karla Sartor -- Karla Sartor Montana State University - LRES [EMAIL PROTECTED] __ [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
RE: [R] list of lists question
From: Karla Sartor Hello all, As a general programming question I can't seem to figure out how to make a list of lists in R. As matrices won't work as they have to be rectangular. I am sure that there is an easy solution but... the specific situation is this: - I have created a Tukey confidence interval table and have listed the means that are not significantly different - then using these not significantly different pairs I have created the groups of means that are not significantly different from each other the issue then is that many of these lists are subsets of other lists and I need to check for this. Below is a little program is illustrate the issue a=c(1,1,1,1,1) # generate the first list b=c(2,2,2)# generate a second list c=c(a,b) #combine them cat(c, \n)# and print 1 1 1 1 1 2 2 2 # this is 1-D!!! ahh d=list(a,b)# make a list of a and b d # and print [[1]] #this is exactly what I want, but continue [1] 1 1 1 1 1 [[2]] [1] 2 2 2 e=list(d,a) # now on the next iteration I need to add another list to this list of lists e # and print [[1]] # ahh all hell has broken loose and this is not what I want [[1]][[1]] # desired result below [1] 1 1 1 1 1 [[1]][[2]] [1] 2 2 2 [[2]] [1] 1 1 1 1 1 - desired result #wrong code but this is what I want to happen a=c(1,1,1,1,1,1,1) for(i in 1:5) { a=list(a,1:5) } output I want is (something like) [1] 1 1 1 1 1 1 1 [2] 1 2 3 4 5 [3] 1 2 3 4 5 [4] 1 2 3 4 5 [5] 1 2 3 4 5 [6] 1 2 3 4 5 so then I could call cat(a[1]) and get 1 1 1 1 1 1 1 1 and cat(a[2]) and get 1 2 3 4 5 Anyone know the answer (hopefully simple) Indeed: Lists are vectors. You use c() to concatenate vectors, so you also use it for lists. E.g., a - list(rep(1, 5)) for (i in 1:2) a - c(a, list(1:5)) a [[1]] [1] 1 1 1 1 1 [[2]] [1] 1 2 3 4 5 [[3]] [1] 1 2 3 4 5 Andy Cheers, Karla Sartor -- Karla Sartor Montana State University - LRES [EMAIL PROTECTED] __ [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 __ [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
Re: [R] list of lists question
Is the following more like what you want: a=c(1,1,1,1,1) # generate the first list b=c(2,2,2)# generate a second list d=list(a,b)# make a list of a and b ( e=c(d,a) ) [[1]] [1] 1 1 1 1 1 [[2]] [1] 2 2 2 [[3]] [1] 1 [[4]] [1] 1 [[5]] [1] 1 [[6]] [1] 1 [[7]] [1] 1 If no, have you read sec. 6 in An Introduction to R [the first option available from help.start()]? In this example, note that e[1] is a list with only one attributes, namely the vector 1 1 1 1 1; e[[1]] is not a list but that vector itself. hope this helps. spencer graves Karla Sartor wrote: Hello all, As a general programming question I can't seem to figure out how to make a list of lists in R. As matrices won't work as they have to be rectangular. I am sure that there is an easy solution but... the specific situation is this: - I have created a Tukey confidence interval table and have listed the means that are not significantly different - then using these not significantly different pairs I have created the groups of means that are not significantly different from each other the issue then is that many of these lists are subsets of other lists and I need to check for this. Below is a little program is illustrate the issue a=c(1,1,1,1,1) # generate the first list b=c(2,2,2)# generate a second list c=c(a,b) #combine them cat(c, \n)# and print 1 1 1 1 1 2 2 2 # this is 1-D!!! ahh d=list(a,b)# make a list of a and b d # and print [[1]] #this is exactly what I want, but continue [1] 1 1 1 1 1 [[2]] [1] 2 2 2 e=list(d,a) # now on the next iteration I need to add another list to this list of lists e # and print [[1]] # ahh all hell has broken loose and this is not what I want [[1]][[1]] # desired result below [1] 1 1 1 1 1 [[1]][[2]] [1] 2 2 2 [[2]] [1] 1 1 1 1 1 - desired result #wrong code but this is what I want to happen a=c(1,1,1,1,1,1,1) for(i in 1:5) { a=list(a,1:5) } output I want is (something like) [1] 1 1 1 1 1 1 1 [2] 1 2 3 4 5 [3] 1 2 3 4 5 [4] 1 2 3 4 5 [5] 1 2 3 4 5 [6] 1 2 3 4 5 so then I could call cat(a[1]) and get 1 1 1 1 1 1 1 1 and cat(a[2]) and get 1 2 3 4 5 Anyone know the answer (hopefully simple) Cheers, Karla Sartor -- Karla Sartor Montana State University - LRES [EMAIL PROTECTED] __ [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 -- Spencer Graves, PhD, Senior Development Engineer O: (408)938-4420; mobile: (408)655-4567 __ [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
[R] list - environment coercion
Hi all, there is environment-list coercion, i.e. as.list.environment. Is there any list-environment coercion? thank you. -- Valery. __ [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
Re: [R] list - environment coercion
Hi Valery, a simple way to do it might be the following: lis - list(a=10, b=20, d=x) e1 - new.env() for(i in 1:length(lis)) assign(names(lis)[i], lis[[i]], envir=e1) d get(d, env=e1) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Valery A.Khamenya [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, November 09, 2004 4:56 PM Subject: [R] list - environment coercion Hi all, there is environment-list coercion, i.e. as.list.environment. Is there any list-environment coercion? thank you. -- Valery. __ [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 __ [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
[R] List seems to drop empty levels of factors when containing them
Greetings R community, I am curious about the following behaviour: if I define a factor, and then store a subset of it in a list, the stored version seems to drop levels that were not included in the subset. E.g. .. mask - c(T, F) grp.1 - factor(c(1,2)) list(grp.1) [[1]] [1] 1 2 Levels: 1 2 list(grp.1[mask]) [[1]] [1] 1 Levels: 1 It is as though the list were redefining the factor and dropping empty levels. I would like to keep them (I am using the list for a two-dimensional tapply). Is there any way to avoid this? I'm using R 2.0.0 on FreeBSD 5.2.1. Thanks, Andrew -- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : [EMAIL PROTECTED] PO Box 441133W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion. __ [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
RE: [R] List seems to drop empty levels of factors when containin g them
I don't get the same result, do you have a package loaded that would change the default behavior (such as Hmisc)? list(grp.1) [[1]] [1] 1 2 Levels: 1 2 list(grp.1[mask]) [[1]] [1] 1 Levels: 1 2 library(Hmisc) snip list(grp.1[mask]) [[1]] [1] 1 Levels: 1 --Matt version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor0.0 year 2004 month10 day 04 language R -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Andrew Robinson Sent: Tuesday, November 09, 2004 19:44 PM To: R-Help Discussion Cc: Andrew Robinson Subject: [R] List seems to drop empty levels of factors when containing them Greetings R community, I am curious about the following behaviour: if I define a factor, and then store a subset of it in a list, the stored version seems to drop levels that were not included in the subset. E.g. .. mask - c(T, F) grp.1 - factor(c(1,2)) list(grp.1) [[1]] [1] 1 2 Levels: 1 2 list(grp.1[mask]) [[1]] [1] 1 Levels: 1 It is as though the list were redefining the factor and dropping empty levels. I would like to keep them (I am using the list for a two-dimensional tapply). Is there any way to avoid this? I'm using R 2.0.0 on FreeBSD 5.2.1. Thanks, Andrew -- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : [EMAIL PROTECTED] PO Box 441133W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion. __ [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 __ [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
Re: [R] List seems to drop empty levels of factors when containing them
Andrew Robinson wrote: Greetings R community, I am curious about the following behaviour: if I define a factor, and then store a subset of it in a list, the stored version seems to drop levels that were not included in the subset. E.g. .. mask - c(T, F) grp.1 - factor(c(1,2)) list(grp.1) [[1]] [1] 1 2 Levels: 1 2 list(grp.1[mask]) [[1]] [1] 1 Levels: 1 It is as though the list were redefining the factor and dropping empty levels. I would like to keep them (I am using the list for a two-dimensional tapply). Is there any way to avoid this? I'm using R 2.0.0 on FreeBSD 5.2.1. Thanks, Andrew Andrew, I cannot replicate this with R-2.0.0 patched on Win2000Pro: mask - c(T, F) grp.1 - factor(c(1,2)) list(grp.1) [[1]] [1] 1 2 Levels: 1 2 grp.1[mask] [1] 1 Levels: 1 2 list(grp.1[mask]) [[1]] [1] 1 Levels: 1 2 --sundar __ [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
Re: [R] List seems to drop empty levels of factors when containin g them
Matt, very astute - thanks. I did indeed have Hmisc loaded. Andrew On Tue, Nov 09, 2004 at 08:12:57PM -0800, Austin, Matt wrote: I don't get the same result, do you have a package loaded that would change the default behavior (such as Hmisc)? list(grp.1) [[1]] [1] 1 2 Levels: 1 2 list(grp.1[mask]) [[1]] [1] 1 Levels: 1 2 library(Hmisc) snip list(grp.1[mask]) [[1]] [1] 1 Levels: 1 --Matt version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major2 minor0.0 year 2004 month10 day 04 language R -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Andrew Robinson Sent: Tuesday, November 09, 2004 19:44 PM To: R-Help Discussion Cc: Andrew Robinson Subject: [R] List seems to drop empty levels of factors when containing them Greetings R community, I am curious about the following behaviour: if I define a factor, and then store a subset of it in a list, the stored version seems to drop levels that were not included in the subset. E.g. .. mask - c(T, F) grp.1 - factor(c(1,2)) list(grp.1) [[1]] [1] 1 2 Levels: 1 2 list(grp.1[mask]) [[1]] [1] 1 Levels: 1 It is as though the list were redefining the factor and dropping empty levels. I would like to keep them (I am using the list for a two-dimensional tapply). Is there any way to avoid this? I'm using R 2.0.0 on FreeBSD 5.2.1. Thanks, Andrew -- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : [EMAIL PROTECTED] PO Box 441133W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion. __ [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 __ [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 -- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : [EMAIL PROTECTED] PO Box 441133W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion. __ [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
[R] list files ignoring the case option
Sorry if this is a question more on regular expressions. I am dealing with several files which have been badly named. For example the files are given either the extensions txt, TXT or Txt. I wish to select all those files ending with 'txt' ignoring case. Here is how I would do it in bash (Redhat FC2) : touch a1.txt a2.TXT a3.Txt txt.control TXT.control ls -1 | grep -i txt$ Here is how I am currently doing it in R a - list.files(all.files=T) grep( txt$, a, ignore.case=T, value=T ) Is it possible for me to modify the following line to include ignore case option ? a - list.files( pattern=txt$ ) Thank you. Regards, Adai __ [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
Re: [R] list files ignoring the case option
On Thu, 4 Nov 2004, Adaikalavan Ramasamy wrote: Sorry if this is a question more on regular expressions. I am dealing with several files which have been badly named. For example the files are given either the extensions txt, TXT or Txt. I wish to select all those files ending with 'txt' ignoring case. Here is how I would do it in bash (Redhat FC2) : touch a1.txt a2.TXT a3.Txt txt.control TXT.control ls -1 | grep -i txt$ Here is how I am currently doing it in R a - list.files(all.files=T) grep( txt$, a, ignore.case=T, value=T ) I'd write that in one line, but it seems as good a way as any. Is it possible for me to modify the following line to include ignore case option ? a - list.files( pattern=txt$ ) Not as such. First, I think you want \\.txt$ there if you do mean file extensions. You can use a regexp that ignores case, though, e.g. \\.[Tt]{Xx][Tt]. But I would just use your original idea, which is essentially what ls() is doing internally and is self-documenting. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [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
Re: [R] list files ignoring the case option
Thanks to Sundar Dorai-Raj, Prof. Ripley and Berton Gunter for the solution. I think I will take Prof. Ripley's suggestion and stick with my initial solution for code readability but I am sure the regexp stuff will come handy next time. On Thu, 2004-11-04 at 15:10, Prof Brian Ripley wrote: On Thu, 4 Nov 2004, Adaikalavan Ramasamy wrote: Sorry if this is a question more on regular expressions. I am dealing with several files which have been badly named. For example the files are given either the extensions txt, TXT or Txt. I wish to select all those files ending with 'txt' ignoring case. Here is how I would do it in bash (Redhat FC2) : touch a1.txt a2.TXT a3.Txt txt.control TXT.control ls -1 | grep -i txt$ Here is how I am currently doing it in R a - list.files(all.files=T) grep( txt$, a, ignore.case=T, value=T ) I'd write that in one line, but it seems as good a way as any. Is it possible for me to modify the following line to include ignore case option ? a - list.files( pattern=txt$ ) Not as such. First, I think you want \\.txt$ there if you do mean file extensions. You can use a regexp that ignores case, though, e.g. \\.[Tt]{Xx][Tt]. But I would just use your original idea, which is essentially what ls() is doing internally and is self-documenting. __ [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
[R] R list
Hi Is there any function to get the name of the components of a given list object? ok. [[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
RE: [R] R list
names() is what you want, if i understand your question correctly. cheers, robert -Original Message- From: Leonardo L Miceli [mailto:[EMAIL PROTECTED] Sent: Friday, October 29, 2004 3:22 PM To: [EMAIL PROTECTED] Subject: [R] R list Hi Is there any function to get the name of the components of a given list object? ok. [[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 __ [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
RE: [R] R list
Yes, names(). Andy From: Leonardo L Miceli Hi Is there any function to get the name of the components of a given list object? ok. [[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 __ [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
Re: [R] R list
What about names() ? Giovanni Date: Fri, 29 Oct 2004 11:21:35 -0300 From: Leonardo L Miceli [EMAIL PROTECTED] Sender: [EMAIL PROTECTED] Cc: Precedence: list Hi Is there any function to get the name of the components of a given list object? ok. [[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 -- __ [ ] [ Giovanni Petris [EMAIL PROTECTED] ] [ Department of Mathematical Sciences ] [ University of Arkansas - Fayetteville, AR 72701 ] [ Ph: (479) 575-6324, 575-8630 (fax) ] [ http://definetti.uark.edu/~gpetris/ ] [__] __ [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
Re: [R] Proposal for New R List: Criticism? Comments?
It seems to me that \concept{} is simply another code for My keyword is your search term. I do not consider myself to be one of the better informed users of R, yet the frequency with which I resort to a full text search is less than once a month. For such an infrequent task, I find it no problem to fire off a full text search of the help files and occupy myself otherwise for a minute or two. Jim __ [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
RE: [R] Proposal for New R List: Criticism? Comments?
Hi John et al. I'm coming late to this thread (because of vacation), JohnF == John Fox [EMAIL PROTECTED] on Fri, 10 Sep 2004 10:56:51 -0400 writes: JohnF Dear Brian et al., JohnF Jonathan's search site is excellent -- I use it JohnF frequently -- and for some reason new users seem JohnF unaware of help.search(), which, despite the fact JohnF that it searches only in installed packages, I also JohnF find very useful. yes and yes. JohnF A couple of comments, however: First, if help pages JohnF from all packages were available at a central JohnF location -- e.g., at CRAN -- help.search() could have JohnF an option to search that location. Second, I still JohnF feel that it would be useful to provide some other JohnF way of searching the space of all available JohnF functions. One idea, which I mentioned in an earlier JohnF message on this thread, would be a keyword system JohnF (again, different from the current set of standard JohnF keywords). \concept{} was introduced for this JohnF The keywords could be accessed by help.search() and this happens (by default) for \concept{} entries JohnF and also compiled into an index. this doesn't happen yet. The ``real problem'' of course is that package authors need to write all these \concept{} entries before such an index can really become useful. Martin Maechler -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Friday, September 10, 2004 5:26 AM To: Jonathan Baron Cc: Adaikalavan Ramasamy; John Fox; R-help; 'Berton Gunter' Subject: Re: [R] Proposal for New R List: Criticism? Comments? On Fri, 10 Sep 2004, Jonathan Baron wrote: On 09/10/04 03:54, Adaikalavan Ramasamy wrote: There is another issue to be considered. Currently you need to have the relevant packages installed before help.search() bring it up. My work around this is to install all available packages just in case the function I need is nestled in some non-standard packages. I also update them rather frequently. I do this too, at my search site (where frequently=monthly) and you can search functions only, and use Boolean search expressions and phrases. But right now the entire set of packages takes about 885 meg (if I'm reading du correctly), which is less than my very modest collection of digital photos, and a tiny fraction of a 3-year-old standard hard disk. In other words, it is no big deal to install all the packages if you have your own computer. I am seeing about 520Mb for all base + CRAN packages under 1.9.1, and it will be rather less under 2.0.0 as more parts are stored compressed. BioC is a lot larger. It is however, a BIG deal to install *all* the packages and am I currently 10 short since they depend on other software that I do not have a licence for or will not compile (and there are three others I cannot reinstall using current gcc). On AMD64 and Solaris there are several others, and something like 20 do not install on Windows. (I could use --install-fake as the CRAN checks do, but I have the almost complete set installed to test R changes, not test packages.) So I do see some merit in having a full-text search for R help available at some URL, as Jonathan has kindly provided. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [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
RE: [R] Proposal for New R List: Criticism? Comments?
Dear Martin, Thanks for pointing this out -- I'm ashamed to say that I forgot about \concept{} entries. As you say (aside from people stupidly forgetting that they exist), the problem is to get people to use them. How about requiring one or more concept entries for each help file? Regards, John -Original Message- From: Martin Maechler [mailto:[EMAIL PROTECTED] Sent: Friday, September 17, 2004 7:57 AM To: John Fox Cc: 'R-help' Subject: RE: [R] Proposal for New R List: Criticism? Comments? Hi John et al. I'm coming late to this thread (because of vacation), JohnF == John Fox [EMAIL PROTECTED] on Fri, 10 Sep 2004 10:56:51 -0400 writes: JohnF Dear Brian et al., JohnF Jonathan's search site is excellent -- I use it JohnF frequently -- and for some reason new users seem JohnF unaware of help.search(), which, despite the fact JohnF that it searches only in installed packages, I also JohnF find very useful. yes and yes. JohnF A couple of comments, however: First, if help pages JohnF from all packages were available at a central JohnF location -- e.g., at CRAN -- help.search() could have JohnF an option to search that location. Second, I still JohnF feel that it would be useful to provide some other JohnF way of searching the space of all available JohnF functions. One idea, which I mentioned in an earlier JohnF message on this thread, would be a keyword system JohnF (again, different from the current set of standard JohnF keywords). \concept{} was introduced for this JohnF The keywords could be accessed by help.search() and this happens (by default) for \concept{} entries JohnF and also compiled into an index. this doesn't happen yet. The ``real problem'' of course is that package authors need to write all these \concept{} entries before such an index can really become useful. Martin Maechler -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Friday, September 10, 2004 5:26 AM To: Jonathan Baron Cc: Adaikalavan Ramasamy; John Fox; R-help; 'Berton Gunter' Subject: Re: [R] Proposal for New R List: Criticism? Comments? On Fri, 10 Sep 2004, Jonathan Baron wrote: On 09/10/04 03:54, Adaikalavan Ramasamy wrote: There is another issue to be considered. Currently you need to have the relevant packages installed before help.search() bring it up. My work around this is to install all available packages just in case the function I need is nestled in some non-standard packages. I also update them rather frequently. I do this too, at my search site (where frequently=monthly) and you can search functions only, and use Boolean search expressions and phrases. But right now the entire set of packages takes about 885 meg (if I'm reading du correctly), which is less than my very modest collection of digital photos, and a tiny fraction of a 3-year-old standard hard disk. In other words, it is no big deal to install all the packages if you have your own computer. I am seeing about 520Mb for all base + CRAN packages under 1.9.1, and it will be rather less under 2.0.0 as more parts are stored compressed. BioC is a lot larger. It is however, a BIG deal to install *all* the packages and am I currently 10 short since they depend on other software that I do not have a licence for or will not compile (and there are three others I cannot reinstall using current gcc). On AMD64 and Solaris there are several others, and something like 20 do not install on Windows. (I could use --install-fake as the CRAN checks do, but I have the almost complete set installed to test R changes, not test packages.) So I do see some merit in having a full-text search for R help available at some URL, as Jonathan has kindly provided. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [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
Re: [R] Proposal for New R List: Criticism? Comments?
On 09/10/04 03:54, Adaikalavan Ramasamy wrote: There is another issue to be considered. Currently you need to have the relevant packages installed before help.search() bring it up. My work around this is to install all available packages just in case the function I need is nestled in some non-standard packages. I also update them rather frequently. I do this too, at my search site (where frequently=monthly) and you can search functions only, and use Boolean search expressions and phrases. But right now the entire set of packages takes about 885 meg (if I'm reading du correctly), which is less than my very modest collection of digital photos, and a tiny fraction of a 3-year-old standard hard disk. In other words, it is no big deal to install all the packages if you have your own computer. Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron R search page: http://finzi.psych.upenn.edu/ __ [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
Re: [R] Proposal for New R List: Criticism? Comments?
On Fri, 10 Sep 2004, Jonathan Baron wrote: On 09/10/04 03:54, Adaikalavan Ramasamy wrote: There is another issue to be considered. Currently you need to have the relevant packages installed before help.search() bring it up. My work around this is to install all available packages just in case the function I need is nestled in some non-standard packages. I also update them rather frequently. I do this too, at my search site (where frequently=monthly) and you can search functions only, and use Boolean search expressions and phrases. But right now the entire set of packages takes about 885 meg (if I'm reading du correctly), which is less than my very modest collection of digital photos, and a tiny fraction of a 3-year-old standard hard disk. In other words, it is no big deal to install all the packages if you have your own computer. I am seeing about 520Mb for all base + CRAN packages under 1.9.1, and it will be rather less under 2.0.0 as more parts are stored compressed. BioC is a lot larger. It is however, a BIG deal to install *all* the packages and am I currently 10 short since they depend on other software that I do not have a licence for or will not compile (and there are three others I cannot reinstall using current gcc). On AMD64 and Solaris there are several others, and something like 20 do not install on Windows. (I could use --install-fake as the CRAN checks do, but I have the almost complete set installed to test R changes, not test packages.) So I do see some merit in having a full-text search for R help available at some URL, as Jonathan has kindly provided. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [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
RE: [R] Proposal for New R List: Criticism? Comments?
Dear Brian et al., Jonathan's search site is excellent -- I use it frequently -- and for some reason new users seem unaware of help.search(), which, despite the fact that it searches only in installed packages, I also find very useful. A couple of comments, however: First, if help pages from all packages were available at a central location -- e.g., at CRAN -- help.search() could have an option to search that location. Second, I still feel that it would be useful to provide some other way of searching the space of all available functions. One idea, which I mentioned in an earlier message on this thread, would be a keyword system (again, different from the current set of standard keywords). The keywords could be accessed by help.search() and also compiled into an index. Regards, John -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Friday, September 10, 2004 5:26 AM To: Jonathan Baron Cc: Adaikalavan Ramasamy; John Fox; R-help; 'Berton Gunter' Subject: Re: [R] Proposal for New R List: Criticism? Comments? On Fri, 10 Sep 2004, Jonathan Baron wrote: On 09/10/04 03:54, Adaikalavan Ramasamy wrote: There is another issue to be considered. Currently you need to have the relevant packages installed before help.search() bring it up. My work around this is to install all available packages just in case the function I need is nestled in some non-standard packages. I also update them rather frequently. I do this too, at my search site (where frequently=monthly) and you can search functions only, and use Boolean search expressions and phrases. But right now the entire set of packages takes about 885 meg (if I'm reading du correctly), which is less than my very modest collection of digital photos, and a tiny fraction of a 3-year-old standard hard disk. In other words, it is no big deal to install all the packages if you have your own computer. I am seeing about 520Mb for all base + CRAN packages under 1.9.1, and it will be rather less under 2.0.0 as more parts are stored compressed. BioC is a lot larger. It is however, a BIG deal to install *all* the packages and am I currently 10 short since they depend on other software that I do not have a licence for or will not compile (and there are three others I cannot reinstall using current gcc). On AMD64 and Solaris there are several others, and something like 20 do not install on Windows. (I could use --install-fake as the CRAN checks do, but I have the almost complete set installed to test R changes, not test packages.) So I do see some merit in having a full-text search for R help available at some URL, as Jonathan has kindly provided. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [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
Re: [R] Proposal for New R List: Criticism? Comments?
Just finished updating and installing new packages from CRAN and BioConductor (including annotation data) and am happy to say that my R has just exceeded the 1 GB mark. On Fri, 2004-09-10 at 10:11, Jonathan Baron wrote: On 09/10/04 03:54, Adaikalavan Ramasamy wrote: There is another issue to be considered. Currently you need to have the relevant packages installed before help.search() bring it up. My work around this is to install all available packages just in case the function I need is nestled in some non-standard packages. I also update them rather frequently. I do this too, at my search site (where frequently=monthly) and you can search functions only, and use Boolean search expressions and phrases. But right now the entire set of packages takes about 885 meg (if I'm reading du correctly), which is less than my very modest collection of digital photos, and a tiny fraction of a 3-year-old standard hard disk. In other words, it is no big deal to install all the packages if you have your own computer. Jon __ [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
[R] Proposal for New R List: Criticism? Comments?
Folks: I would like to propose a new R list, tentatively labeled r-contents. I wish to briefly explain the purpose and format here and solicit public comments, pro or con, so feel free to criticize or suggest a better name and other improvements or alternatives. R presently consists of a suite of about a dozen core recommended packages and several hundred contributed packages comprising thousands -- perhaps tens of thousands -- of functions. Hopefully, this will continue to grow rapidly. No one can possibly keep track of all of this, and it is therefore a daunting task for someone seeking specific functionality to find it, especially when they are relatively new to R. Of course, R and CRAN (and Google and ...) have various search capabilities that help, but these are essentially keyword-based and so require the searcher to guess search terms that are at least reasonably close to function names and keywords. A lot of the time this works, but it can be tedious; some of the time one guesses wrong, and it doesn't work. S-Plus and much other software addresses this by providing a semantically-based Contents Index (or something like it) in their Help functionality. I find this quite useful, but creating and maintaining such an index seems to me to be extremely labor intensive, fraught with its own issues (what heading should I look under?), and, I think, not a good fit to the spirit and dynamics of R anyway. Not surprisingly, as a result, many of the questions addressed to r-help are of the form: I want to do such and such. How do I do it? While this certainly gives answers, I think the breadth of r-help and its etiquette and posting conventions result in an abruptness to many of our replies (Read the posting guide! Read the Help files and do what they say!) that discourages many users -- especially casual ones -- from posting questions, and thus may thus discourage use of R. Clearly, if true, this is not a good thing; on the other hand, I think that given r-help's purpose and practices, many of these abrupt replies may well be appropriate (I'm a curmudgeon at heart!). Hence, there is a mismatch between user needs and r-help services. To address this mismatch, I would like to propose a new list, r-contents, to essentially serve the same purpose as the S-Plus Contents index. Hence, it would serve as a place for users to post queries ** only ** of the form: I want to do such and such. How do I do it? and receive answers that would all be **single phrases ** of the form package suchandsuch or ?suchandsuchfunction. No further explanations regarding usage would be provided, though users would be free to follow up answers with private questions to the responder, although there should be no expectation of any response. Queries could be framed with as much or as little supporting detail as desired, with the obvious consequence that a more clearly framed question would be more likely to get a (better) response. No other posting conventions (aside from the usual ones regarding civility and adherence to topic) would be expected. My hope is that such a list would both reduce unnecessary traffic on r-help and satisfy a genuine need in a less threatening way. I can certainly see downsides (I often learn a lot from How can I do this? queries), but I think, on balance, this approach might be useful. So I would like to subject the idea to public scrutiny and criticism, as well as the opportunity for improvement from suggested modifications or alternatives. If it's useful, this will be recognized; if it's not and/or no one is interested, that, too, will be made manifest. I would be especially grateful for the opinions of casual users or newbies, either publicly or privately. Cheers, -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA The business of the statistician is to catalyze the scientific learning process. - George E. P. Box [[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
Re: [R] Proposal for New R List: Criticism? Comments?
I think that a lot of posts on r-help are exactly of the form you suggest: How do I do X? Answer: Use Y. (Or maybe, Use Y. And next time RTFM. But so what. The answer is still there.) Often, when the answer is not of that form, the question is unclear. In other cases, the questioner is apparently asking for general statistical advice, rather than which package to use. In sum, I don't think the new list is needed. I do not want to archive it. I think that, if a questioner fails to find an answer because the terms he would use do not happen to be indexed in help.search(), etc., then he has the option of using my search engine as a fallback, where it is likely that someone else has used his favored terms. Jon -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron R search page: http://finzi.psych.upenn.edu/ __ [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
RE: [R] Proposal for New R List: Criticism? Comments?
Dear Bert, I believe that you've identified an important issue -- and one that's occasionally been discussed on this list previously -- but I'm not sure that another email list is a good solution. Some method of indexing functions in packages that would allow people to more easily locate them (e.g., author-supplied [i.e., not simply standard] keywords for each public object in a package) seems to me a more promising approach. Regards, John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Berton Gunter Sent: Thursday, September 09, 2004 11:50 AM To: [EMAIL PROTECTED] Subject: [R] Proposal for New R List: Criticism? Comments? Folks: I would like to propose a new R list, tentatively labeled r-contents. I wish to briefly explain the purpose and format here and solicit public comments, pro or con, so feel free to criticize or suggest a better name and other improvements or alternatives. R presently consists of a suite of about a dozen core recommended packages and several hundred contributed packages comprising thousands -- perhaps tens of thousands -- of functions. Hopefully, this will continue to grow rapidly. No one can possibly keep track of all of this, and it is therefore a daunting task for someone seeking specific functionality to find it, especially when they are relatively new to R. Of course, R and CRAN (and Google and ...) have various search capabilities that help, but these are essentially keyword-based and so require the searcher to guess search terms that are at least reasonably close to function names and keywords. A lot of the time this works, but it can be tedious; some of the time one guesses wrong, and it doesn't work. S-Plus and much other software addresses this by providing a semantically-based Contents Index (or something like it) in their Help functionality. I find this quite useful, but creating and maintaining such an index seems to me to be extremely labor intensive, fraught with its own issues (what heading should I look under?), and, I think, not a good fit to the spirit and dynamics of R anyway. Not surprisingly, as a result, many of the questions addressed to r-help are of the form: I want to do such and such. How do I do it? While this certainly gives answers, I think the breadth of r-help and its etiquette and posting conventions result in an abruptness to many of our replies (Read the posting guide! Read the Help files and do what they say!) that discourages many users -- especially casual ones -- from posting questions, and thus may thus discourage use of R. Clearly, if true, this is not a good thing; on the other hand, I think that given r-help's purpose and practices, many of these abrupt replies may well be appropriate (I'm a curmudgeon at heart!). Hence, there is a mismatch between user needs and r-help services. To address this mismatch, I would like to propose a new list, r-contents, to essentially serve the same purpose as the S-Plus Contents index. Hence, it would serve as a place for users to post queries ** only ** of the form: I want to do such and such. How do I do it? and receive answers that would all be **single phrases ** of the form package suchandsuch or ?suchandsuchfunction. No further explanations regarding usage would be provided, though users would be free to follow up answers with private questions to the responder, although there should be no expectation of any response. Queries could be framed with as much or as little supporting detail as desired, with the obvious consequence that a more clearly framed question would be more likely to get a (better) response. No other posting conventions (aside from the usual ones regarding civility and adherence to topic) would be expected. My hope is that such a list would both reduce unnecessary traffic on r-help and satisfy a genuine need in a less threatening way. I can certainly see downsides (I often learn a lot from How can I do this? queries), but I think, on balance, this approach might be useful. So I would like to subject the idea to public scrutiny and criticism, as well as the opportunity for improvement from suggested modifications or alternatives. If it's useful, this will be recognized; if it's not and/or no one is interested, that, too, will be made manifest. I would be especially grateful for the opinions of casual users or newbies, either publicly or privately. Cheers, -- Bert Gunter Genentech Non-Clinical Statistics South San Francisco, CA __ [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
Re: [R] List dimention labels to plots of components
White, Charles E WRAIR-Wash DC wrote: It is frustrating to see the labels I want in the dimensions of a list but not be able to extract those labels into titles for plots generated from component objects. If someone could set me straight, I would appreciate it. For your amusement, I have provided an example of the Byzantine code I am currently using to avoid loops: The code below works perfectly. I don't get the point what you are looking for Uwe Ligges # Simulate ANOVA type test data sex-c(rep(1,8),rep(0,8)) dose-c(rep(1,4),rep(0,4)) treatment-c(rep(1,2),rep(0,2)) fix-sex+dose+treatment Response-fix+rnorm(16) Sex-rep(Male,16) Sex[sex==0]-Female Dose-rep(High,16) Dose[dose==0]-Low Treatment-rep(A,16) Treatment[treatment==0]-B dat-data.frame(Sex,Dose,Treatment,fix,Response) # Redundant Transfer and Execution of Dimension ID? mymod-function(x){ model-lm(Response~Sex,data=x) list(model,Dose=x$Dose[1],Treatment=x$Treatment[1])} myplt-function(x){ plot(x[[1]],main=paste(x$Dose,/,x$Treatment,sep=))} # Generate list of Model Estimates dat.lm-by(dat,list(Dose=dat$Dose,Treatment=dat$Treatment),mymod) # Execute plots with labels pdf(file=junk.pdf,height=7.5,width=10) par(mfrow=c(2,2)) bitbucket-lapply(dat.lm,myplt) dev.off() Charles E. White, Senior Biostatistician, MS Walter Reed Army Institute of Research 503 Robert Grant Ave., Room 1w102 Silver Spring, MD 20910-1557 301 319-9781 Personal/Professional Site: http://users.starpower.net/cwhite571/professional/ __ [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 __ [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
RE: [R] List dimention labels to plots of components
My goal is more efficient code for something I anticipate doing a lot. My example code from my first message works because I insert a seemingly redundant recording of Dose Treatment in the list generated in the by command. Since Dose Treatment are already recorded in the dimensions of the list, I would like to pass those dimensions into the function executed by lapply. That may or may not be possible. # Append the following code to my message of 8/19 # Dose Treatment go to list without separate user code to insert them dat.lm2-by(dat,list(Dose=dat$Dose,Treatment=dat$Treatment), function(x) lm(Response~Sex,data=x)) dimnames(dat.lm2) dat.lm2[Low,B] # lapply uses dimnames to select objects but does not appear to pass # dimnames with object lapply(dat.lm2,dimnames) lapply(dat.lm2,names) lapply(dat.lm2,function(x) print(x)[1:13]) Thanks for your help. Chuck __ [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
[R] List dimention labels to plots of components
It is frustrating to see the labels I want in the dimensions of a list but not be able to extract those labels into titles for plots generated from component objects. If someone could set me straight, I would appreciate it. For your amusement, I have provided an example of the Byzantine code I am currently using to avoid loops: # Simulate ANOVA type test data sex-c(rep(1,8),rep(0,8)) dose-c(rep(1,4),rep(0,4)) treatment-c(rep(1,2),rep(0,2)) fix-sex+dose+treatment Response-fix+rnorm(16) Sex-rep(Male,16) Sex[sex==0]-Female Dose-rep(High,16) Dose[dose==0]-Low Treatment-rep(A,16) Treatment[treatment==0]-B dat-data.frame(Sex,Dose,Treatment,fix,Response) # Redundant Transfer and Execution of Dimension ID? mymod-function(x){ model-lm(Response~Sex,data=x) list(model,Dose=x$Dose[1],Treatment=x$Treatment[1])} myplt-function(x){ plot(x[[1]],main=paste(x$Dose,/,x$Treatment,sep=))} # Generate list of Model Estimates dat.lm-by(dat,list(Dose=dat$Dose,Treatment=dat$Treatment),mymod) # Execute plots with labels pdf(file=junk.pdf,height=7.5,width=10) par(mfrow=c(2,2)) bitbucket-lapply(dat.lm,myplt) dev.off() Charles E. White, Senior Biostatistician, MS Walter Reed Army Institute of Research 503 Robert Grant Ave., Room 1w102 Silver Spring, MD 20910-1557 301 319-9781 Personal/Professional Site: http://users.starpower.net/cwhite571/professional/ __ [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
[R] list of frames without first element
R-help, I have a list of several data frames. I want to compute the rowSums of the columns of these data frames but first one. Something like this lapply(my.list,rowSums) Thank you Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] list of frames without first element
From: Luis Rideau Cruz R-help, I have a list of several data frames. I want to compute the rowSums of the columns of these data frames but first one. Something like this lapply(my.list,rowSums) You're almost there: lapply(my.list, function(x) rowSums(x[-1])) Andy Thank you Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list of frames without first element
Luis Rideau Cruz wrote: R-help, I have a list of several data frames. I want to compute the rowSums of the columns of these data frames but first one. ... but first data.frame or but first column? but first data.frame: lapply(my.list[-1], rowSums) but first column: lapply(my.list, function(x) rowSums(x[,-1])) Uwe Ligges Something like this lapply(my.list,rowSums) Thank you Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] list problem
Hi all, I have the folowing frame(there are more columns than shown), 1 2 34 5 Year Total TusWhi Norw 1994 1.00 1830 0 355 1995 1.00 0 00 1995 1.00 0 00 1995 1.00 49104280 695 1997 1.00 0 0 110 1997 0.58 0 00 1997 1.00 0 00 1994 1.00 0 00 1997 1.00 0 40 70 1998 1.00 0 0 1252 1999 1.04 0 740 1999 1.00 0 00 1999 1.02 0 00 1999 1.00 0 00 1999 1.00 0 0 171 1999 1.00 1794 0 229 1999 1.00 035250 1997 1.00 13351185 147 1997 1.00 49251057 4801 1997 1.00 06275 1773 I try to get sum(Total) by Year in which Tus0, sum(Total) by Year in which Whi0,,,and so on. I have done something like this; a-as.list(numeric(3)) for (i in 3:5) { a[[i]]-aggregate(frame[,Total],list(Year=frame$Year, Tus=frame$i0),sum) } The result is something like; Year Tus x 1994 FALSE 49.69 1995 FALSE 49.35 1996 FALSE 56.95 1997 FALSE 57.00 1998 FALSE 57.00 1999 FALSE 58.09 2000 FALSE 56.97 2001 FALSE 57.95 2002 FALSE 57.10 2003 FALSE 56.16 2000 TRUE 1.00 2002 TRUE 1.00 2003 TRUE 2.01 But when I try indexing frame[Tus==TRUE,]I just don't get it Thank you Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list problem
Hi Luis, maybe there are better ways but you could try something like this, n - length(frame) lapply(split(frame, frame$Year), function(x, n.){ res - numeric(n.-2) for(i in 3:n.) res[i-2] - sum(x$Total[x[,i]0.]) res }, n.=n) I hope this helps. Best, Dimitris Dimitris Rizopoulos Doctoral Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Luis Rideau Cruz [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 27, 2004 2:22 PM Subject: [R] list problem Hi all, I have the folowing frame(there are more columns than shown), 1 2 34 5 Year Total TusWhi Norw 1994 1.00 1830 0 355 1995 1.00 0 00 1995 1.00 0 00 1995 1.00 49104280 695 1997 1.00 0 0 110 1997 0.58 0 00 1997 1.00 0 00 1994 1.00 0 00 1997 1.00 0 40 70 1998 1.00 0 0 1252 1999 1.04 0 740 1999 1.00 0 00 1999 1.02 0 00 1999 1.00 0 00 1999 1.00 0 0 171 1999 1.00 1794 0 229 1999 1.00 035250 1997 1.00 13351185 147 1997 1.00 49251057 4801 1997 1.00 06275 1773 I try to get sum(Total) by Year in which Tus0, sum(Total) by Year in which Whi0,,,and so on. I have done something like this; a-as.list(numeric(3)) for (i in 3:5) { a[[i]]-aggregate(frame[,Total],list(Year=frame$Year, Tus=frame$i0),sum) } The result is something like; Year Tus x 1994 FALSE 49.69 1995 FALSE 49.35 1996 FALSE 56.95 1997 FALSE 57.00 1998 FALSE 57.00 1999 FALSE 58.09 2000 FALSE 56.97 2001 FALSE 57.95 2002 FALSE 57.10 2003 FALSE 56.16 2000 TRUE 1.00 2002 TRUE 1.00 2003 TRUE 2.01 But when I try indexing frame[Tus==TRUE,]I just don't get it Thank you Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list problem
This is also the sort of thing tapply() does well: (note that by() and aggregate() are just fancy wrappers for tapply). e.g. tus-tapply(yourframe$Total,list(yourframe$Year,yourframe$Tus0),sum) (One could nest this within an lapply() to loop over the different columns of your frame). Note that the vectors in the list are silently cast to factors for tapply. -- Bert Gunter Non-Clinical Biostatistics Genentech MS: 240B Phone: 650-467-7374 The business of the statistician is to catalyze the scientific learning process. -- George E.P. Box Dimitris Rizopoulos wrote: Hi Luis, maybe there are better ways but you could try something like this, n - length(frame) lapply(split(frame, frame$Year), function(x, n.){ res - numeric(n.-2) for(i in 3:n.) res[i-2] - sum(x$Total[x[,i]0.]) res }, n.=n) I hope this helps. Best, Dimitris Dimitris Rizopoulos Doctoral Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Luis Rideau Cruz [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, July 27, 2004 2:22 PM Subject: [R] list problem Hi all, I have the folowing frame(there are more columns than shown), 1 2 34 5 Year Total TusWhi Norw 1994 1.00 1830 0 355 1995 1.00 0 00 1995 1.00 0 00 1995 1.00 49104280 695 1997 1.00 0 0 110 1997 0.58 0 00 1997 1.00 0 00 1994 1.00 0 00 1997 1.00 0 40 70 1998 1.00 0 0 1252 1999 1.04 0 740 1999 1.00 0 00 1999 1.02 0 00 1999 1.00 0 00 1999 1.00 0 0 171 1999 1.00 1794 0 229 1999 1.00 035250 1997 1.00 13351185 147 1997 1.00 49251057 4801 1997 1.00 06275 1773 I try to get sum(Total) by Year in which Tus0, sum(Total) by Year in which Whi0,,,and so on. I have done something like this; a-as.list(numeric(3)) for (i in 3:5) { a[[i]]-aggregate(frame[,Total],list(Year=frame$Year, Tus=frame$i0),sum) } The result is something like; Year Tus x 1994 FALSE 49.69 1995 FALSE 49.35 1996 FALSE 56.95 1997 FALSE 57.00 1998 FALSE 57.00 1999 FALSE 58.09 2000 FALSE 56.97 2001 FALSE 57.95 2002 FALSE 57.10 2003 FALSE 56.16 2000 TRUE 1.00 2002 TRUE 1.00 2003 TRUE 2.01 But when I try indexing frame[Tus==TRUE,]I just don't get it Thank you Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Luis Ridao Cruz Fiskirannsóknarstovan Nóatún 1 P.O. Box 3051 FR-110 Tórshavn Faroe Islands Phone: +298 353900 Phone(direct): +298 353912 Mobile: +298 580800 Fax: +298 353901 E-mail: [EMAIL PROTECTED] Web:www.frs.fo __ [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] list of S3-methods
how can I get a list of all S3-methods (of a package) such that I know which functions to include in the S3method() in the NAMESPACE-file? Maybe separated by generic=T/F. thx Meinhard Ploner Vienna __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list of S3-methods
Meinhard Ploner wrote: how can I get a list of all S3-methods (of a package) such that I know which functions to include in the S3method() in the NAMESPACE-file? Maybe separated by generic=T/F. thx Meinhard Ploner Vienna Since one you does not register S3 methods (except for the Namespace file), you cannot get such a list very easily. You might want to look for function names with a dot in it and then look whether the second part of that name corresponds to a class. Uwe Ligges __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] list of S3-methods
Meinhard Ploner wrote: how can I get a list of all S3-methods (of a package) such that I know which functions to include in the S3method() in the NAMESPACE-file? Maybe separated by generic=T/F. thx Meinhard Ploner Vienna Since one you does not register S3 methods (except for the Namespace file), you cannot get such a list very easily. You might want to look for function names with a dot in it and then look whether the second part of that name corresponds to a class. Uwe Ligges Thank you. Usually users register S3-methods prior to make libraries or is this possible only for S4 classes? Meinhard Ploner __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html