[R] Converting variance covariance matrix to correlation matrix
Suppose I have a Variance-covariance matrix A. Is there any fast way to calculate correlation matrix from 'A' and vice-versa without emplying any 'for' loop? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Opening more than 1 R console in Windows
On Sun, 18 May 2008, Anh Tran wrote: Hi all, I recently found out that R does not utilize fully the Duo Core capability when you only run one instance of R. How surprising was that? Do you have any programs that do? Very few Windows programs make effective use of multiple CPUs, and of those that do, they do not do so for the sort of tasks R is running routinely. I did some number crunching today and it seems that if I only open 1 R console, it uses 50% of my CPU (either 50-50 or 100-0 on 2 cores). Then, I open the second instance and divide the work into two parts, and run them parallelly, they seems to utilize 100% of my CPU. So, my question would be that: is the computing result the same if I do them this way? Will there any mistake compared to running only one instance at a time? Running multiple instances of R simultaneously is very common practice. (Right now I have 14 instances running on an 8-core machine.) The only thing you need to watch is that you don't save the workspaces in the same place. So wither run them from different directories or (probably better) don't save the workspace. Thank you all. -- Regards, Anh Tran [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting variance covariance matrix to correlation matrix
Arun Kumar Saha wrote: Suppose I have a Variance-covariance matrix A. Is there any fast way to calculate correlation matrix from 'A' and vice-versa without emplying any 'for' loop? C - cov2cor(A) The other way around is ill-defined, but if d is the vector of variances, d - sqrt(diag(A)) A - outer(d, d)*C. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting variance covariance matrix to correlation matrix
check the following: # covariance matrix V - var(matrix(rnorm(10*4), 10, 4)) cov2cor(V) # correlation matrix R - cov2cor(V) # vector of std. dev. sds - rnorm(4)^2 R * sds * rep(sds, each = nrow(R)) I hope it helps. Best, Dimitris Dimitris Rizopoulos 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: Arun Kumar Saha [EMAIL PROTECTED] To: [EMAIL PROTECTED] [EMAIL PROTECTED] Sent: Monday, May 19, 2008 8:32 AM Subject: [R] Converting variance covariance matrix to correlation matrix Suppose I have a Variance-covariance matrix A. Is there any fast way to calculate correlation matrix from 'A' and vice-versa without emplying any 'for' loop? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Opening more than 1 R console in Windows
Le Mon, May 19, 2008 at 07:39:11AM +0100, Prof Brian Ripley a écrit : On Sun, 18 May 2008, Anh Tran wrote: I recently found out that R does not utilize fully the Duo Core capability when you only run one instance of R. How surprising was that? Do you have any programs that do? Very few Windows programs make effective use of multiple CPUs, and of those that do, they do not do so for the sort of tasks R is running routinely. Hello, actually, when I was (wrongly) plotting a 1,500,000 × 8 data frame and had problems because the plot window was redrawn very frequently, I wondered whether this would be one task that could be given to a separate CPU than the one that deals with the command line interface of R. Do you think that it would be possible? Best regards, -- Charles Plessy Wakō, Saitama, Japan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Opening more than 1 R console in Windows
On Mon, 19 May 2008, Charles Plessy wrote: Le Mon, May 19, 2008 at 07:39:11AM +0100, Prof Brian Ripley a écrit : On Sun, 18 May 2008, Anh Tran wrote: I recently found out that R does not utilize fully the Duo Core capability when you only run one instance of R. How surprising was that? Do you have any programs that do? Very few Windows programs make effective use of multiple CPUs, and of those that do, they do not do so for the sort of tasks R is running routinely. Hello, actually, when I was (wrongly) plotting a 1,500,000 × 8 data frame and had problems because the plot window was redrawn very frequently, I wondered whether this would be one task that could be given to a separate CPU than the one that deals with the command line interface of R. Do you think that it would be possible? Not at present. There are other reasons to want to do graphics interaction in a separate thread, but there are complex synchronization issues. (Suppose you start plotting on a device that is currently repainting?) We are moving in that direction, slowly. Best regards, -- Charles Plessy Wakō, Saitama, Japan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RSQLite and undefined symbol:sqlite3_bind_in
Hi All, I tried to install AnnotationDBI like so: source(http://bioconductor.org/biocLite.R;) biocLite(AnnotationDbi) and got this error: Loading required package: RSQLite Error in dyn.load(file, ...) : unable to load shared library '/RHEL3/local/lib64/R/library/ RSQLite/libs/RSQLite.so': /RHEL3/local/lib64/R/library/RSQLite/libs/RSQLite.so: undefined symbol: sqlite3_bind_int Error: package 'RSQLite' could not be loaded Execution halted ERROR: lazy loading failed for package 'AnnotationDbi' ** Removing '/RHEL3/local/lib64/R/library/AnnotationDbi' The downloaded packages are in /RHEL3/tmp/Rtmp6ex1Pz/downloaded_packages Updating HTML index of packages in '.Library' Warning message: In install.packages(pkgs = pkgs, repos = repos, dependencies = dependencies, : installation of package 'AnnotationDbi' had non-zero exit status However, I did install RSQLite and the installation finished with no errors. But: require(RSQLite) Loading required package: RSQLite Error in dyn.load(file, ...) : unable to load shared library '/usr/local/lib64/R/library/RSQLite/ libs/RSQLite.so': /usr/local/lib64/R/library/RSQLite/libs/RSQLite.so: undefined symbol: sqlite3_bind_int The library and file do exist with 755 permissions. My session info: sessionInfo() R version 2.6.2 (2008-02-08) x86_64-unknown-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.U TF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF- 8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_ID ENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] DBI_0.2-4 loaded via a namespace (and not attached): [1] rcompgen_0.1-17 tools_2.6.2 Has anyone a clue? I am not a R user, just the IT person who has to install it, so if you need additional info from inside R, please let me know how to get it. Thanks a lot, Maya [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Startin R from .RData in linux
Hi! Is it possible to start R by clicking the .RData file in linux as in Windows? I've tried with ubuntu hardy using the right button and selecting R, but does not work. Is there any way to set it up? (I know R can by started from the terminal, selecting the appropriate directory). Thanks Agus -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) LLuis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 email: [EMAIL PROTECTED] http://www.ija.csic.es/gt/obster __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Log or diary file
Hi! Is it possible to set a file to which both commands and output would get automatically saved? I've tried with sink(), but only get the output. I mean something like a combined history and sink, as you get with File/Save to File.. in the windows GUI. Tis is done with diary filename in Matlab, and you can state diary on and diary off to control what is being saved to the file. Thanks Agus -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) LLuis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 email: [EMAIL PROTECTED] http://www.ija.csic.es/gt/obster __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] *apply function for arrays?
Hesen Peng wrote: Hi, Thank you so much for the help. apply does work for the first situation. For the second situation, I'm currently using: temp.a-function(i,j){ return(G(M[i,],N[j,])) } temp.v-Vectorize(temp.a) result-outer(1:nrow(M),1:nrow(N),FUN=temp.v) Looks pretty good! Uwe And I wonder whether there are some other ways to do this. On Sun, May 18, 2008 at 3:52 PM, Patrick Burns [EMAIL PROTECTED] wrote: You want to use the 'apply' function. S Poetry has a chapter on higher dimensional arrays that may be of use to you. I don't see a good approach for your second situation other than a double for loop. Unless G is linear, I think all other solutions will be equivalent to a double for loop, though the loops may be hidden. Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Hesen Peng wrote: Hi all, I've recently been writing functions which may deal with very large arrays. And I hope to use *apply functions in the program so that the code may look nicer and the performance may be better in the following two situations. The first situation is: I'm having an array A with dim(A)==c(m,n,p). And I want to apply a function F to a group of elements in A like: 1) F is applied to every group of elements like A[i,j,] for all i and j. or 2) F is applied to every group of elements like A[i,,] for all i, or A[,j,] for all j. The result is then expected to be a m*n-dimensional matrix I'm currently using for loops to do this but I guess there maybe some *apply functions for arrays which may accomplish this task. The second situation is: I'm having two matrix M and N and a function G, which is a function of two arrays. I want to form a matrix R with dim(R)==c(nrow(M),nrow(N)), and R[i,j] - G(M[i,], N[j,]). And I wonder whether I may use some functions like outer to the matrix. Thank you very much and have a nice weekend. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Converting variance covariance matrix to correlation matrix
Peter Dalgaard wrote: Arun Kumar Saha wrote: Suppose I have a Variance-covariance matrix A. Is there any fast way to calculate correlation matrix from 'A' and vice-versa without emplying any 'for' loop? C - cov2cor(A) The other way around is ill-defined, but if d is the vector of variances, Doh. Edited code, but not text... Vector of standard deviations, of course. d - sqrt(diag(A)) A - outer(d, d)*C. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] two curves at one graph
hanen wrote: i try to use par(new=TRUE) i get them at the same graph but the y_axis and x_axis are drowen with two unevenly graduations that graph become unreadable. Hi Hanen, If you want to plot two sets of values that fit into the same range, plot the one with the larger range first, then use the points (or lines) function to plot the other set. For example: x1-c(1.2,2.3,3.4,4.5) # this one has a larger range x2-c(0.3,2.4,4.6,6.8) # plot the one with the wider range plot(x2,col=red) # then the one that fits within the first range points(x1,col=green) If the ranges of the values overlap, but neither range fits in the other: x1-c(4.5,7.9,9.1,9.9) x2-c(0.3,2.4,4.6,6.8) # use ylim to leave enough room on the first plot plot(x2,ylim=range(c(x1,x2)),col=red) points(x1,col=green) If the ranges are really different, you can try gap.plot or twoord.plot in the plotrix package: x1-c(1.2,2.3,3.4,4.5) x2-c(20.3,22.4,34.6,46.8) gap.plot(c(x1,x2),col=c(rep(green,4),rep(red,4)),gap=c(6,18)) # OR twoord.plot(x1,x2) In the above example, gap.plot is probably better for this data. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Select certain elements from dataframe
Hello, I have a specific problem, I have a large dataframe, and after clustering I want to select certain colums, the elements of a subcluster. My dataframe looks like this : colnames(data) [1] 101KF4319097339 102KF4319101170 103KF4319047549 104KF4319046389 [5] 105KF4319013260 106KF4319025582 107KF4319108763 108KF4319047040 [9] 109KF4319060241 110KF4319056658 111KF4319036131 112KF4319097194 . . . [701] 821KS4242126913 822KS4242026026 823KS4242003122 824IHT06020 [705] 825IHT06020 826IHT06005 827IHT06005 My subcluster looks like this xx1 xx1 [1] 101KF4319097339 102KF4319101170 103KF4319047549 104KF4319046389 [5] 125KF4319063638 126KF4319102180 127KF4319107122 128KF4319019607 [9] 135KF4319037854 138KF4319050003 140KF4319069150 152KF4319109279 . . . [125] 795KS4242028634 797KS4242032582 798KS4242035374 127 Levels: 101KF4319097339 102KF4319101170 103KF4319047549 ... 798KS4242035374 Now I want to select all elements from data that are in xx1, I tried data.xx1-data[ ,xx1] but that selects the just the first 127 (127 is the number of elements / length from xx1) elements from data. Any help would be very appreciated :) Sebastian -- View this message in context: http://www.nabble.com/Select-certain-elements-from-dataframe-tp17314209p17314209.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How hist() decides breaks?
Hi Folks, I'd like to know how hist() decides how many cells to use when it ignores my suggestion to use say 'hist(...,breaks=50)'. More specifically, I have the results of 1 simulations, each returning an 8-vector, therefore 8 variables each with 1 values. Some of these 8 have somewhat skew distributions. Say one of these 8 variables is X. I ask for H - hist(X,breaks=50), and get a histogram which usually has a different number of cells than what I intended. For instance, for one of these simulations, the 8 different values of length(H$breaks) are: 70, 44, 38, 68, 50, 40, 46, 45 ?hist tells me A) breaks: one of: * a vector giving the breakpoints between histogram cells, * a single number giving the number of cells for the histogram, * a character string naming an algorithm to compute the number of cells (see Details), * a function to compute the number of cells. In the last three cases the number is a suggestion only. B) The default for 'breaks' is 'Sturges': see 'nclass.Sturges'. If I look at the code for nclass.Sturges() I see function (x) ceiling(log2(length(x)) + 1) and, for length(X) = 1, this gives 15. This is not related to any of the numbers of breaks I actually got, in any way obvious to me. So: Question 1: hist() has apparently ignored my suggestion of break=50. Why? What is the criterion for ignoring? Question 2: Presumably, if it ignores the suggestion, it does something else, of its choice. I would then, perhaps, expect it to fall back to its default, which is (allegedly) Sturges. But the result from nclass.Sturges looks different from what it actually did. So what did it actually do, and how did it decide on this? With thanks, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 19-May-08 Time: 10:31:20 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Select certain elements from dataframe
'xx1' is a 'factor' and you have to convert to a character before selecting: data.xx1-data[ ,as.character(xx1)] On Mon, May 19, 2008 at 5:20 AM, SebastianEck [EMAIL PROTECTED] wrote: Hello, I have a specific problem, I have a large dataframe, and after clustering I want to select certain colums, the elements of a subcluster. My dataframe looks like this : colnames(data) [1] 101KF4319097339 102KF4319101170 103KF4319047549 104KF4319046389 [5] 105KF4319013260 106KF4319025582 107KF4319108763 108KF4319047040 [9] 109KF4319060241 110KF4319056658 111KF4319036131 112KF4319097194 . . . [701] 821KS4242126913 822KS4242026026 823KS4242003122 824IHT06020 [705] 825IHT06020 826IHT06005 827IHT06005 My subcluster looks like this xx1 xx1 [1] 101KF4319097339 102KF4319101170 103KF4319047549 104KF4319046389 [5] 125KF4319063638 126KF4319102180 127KF4319107122 128KF4319019607 [9] 135KF4319037854 138KF4319050003 140KF4319069150 152KF4319109279 . . . [125] 795KS4242028634 797KS4242032582 798KS4242035374 127 Levels: 101KF4319097339 102KF4319101170 103KF4319047549 ... 798KS4242035374 Now I want to select all elements from data that are in xx1, I tried data.xx1-data[ ,xx1] but that selects the just the first 127 (127 is the number of elements / length from xx1) elements from data. Any help would be very appreciated :) Sebastian -- View this message in context: http://www.nabble.com/Select-certain-elements-from-dataframe-tp17314209p17314209.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How hist() decides breaks?
Why don't you specifically tell hist what breaks to use: hist(x, breaks=seq(min(x), max(x), length=50), include.lowest=TRUE) On Mon, May 19, 2008 at 5:31 AM, Ted Harding [EMAIL PROTECTED] wrote: Hi Folks, I'd like to know how hist() decides how many cells to use when it ignores my suggestion to use say 'hist(...,breaks=50)'. More specifically, I have the results of 1 simulations, each returning an 8-vector, therefore 8 variables each with 1 values. Some of these 8 have somewhat skew distributions. Say one of these 8 variables is X. I ask for H - hist(X,breaks=50), and get a histogram which usually has a different number of cells than what I intended. For instance, for one of these simulations, the 8 different values of length(H$breaks) are: 70, 44, 38, 68, 50, 40, 46, 45 ?hist tells me A) breaks: one of: * a vector giving the breakpoints between histogram cells, * a single number giving the number of cells for the histogram, * a character string naming an algorithm to compute the number of cells (see Details), * a function to compute the number of cells. In the last three cases the number is a suggestion only. B) The default for 'breaks' is 'Sturges': see 'nclass.Sturges'. If I look at the code for nclass.Sturges() I see function (x) ceiling(log2(length(x)) + 1) and, for length(X) = 1, this gives 15. This is not related to any of the numbers of breaks I actually got, in any way obvious to me. So: Question 1: hist() has apparently ignored my suggestion of break=50. Why? What is the criterion for ignoring? Question 2: Presumably, if it ignores the suggestion, it does something else, of its choice. I would then, perhaps, expect it to fall back to its default, which is (allegedly) Sturges. But the result from nclass.Sturges looks different from what it actually did. So what did it actually do, and how did it decide on this? With thanks, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 19-May-08 Time: 10:31:20 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How hist() decides breaks?
(Ted Harding) wrote: Hi Folks, I'd like to know how hist() decides how many cells to use when it ignores my suggestion to use say 'hist(...,breaks=50)'. More specifically, I have the results of 1 simulations, each returning an 8-vector, therefore 8 variables each with 1 values. Some of these 8 have somewhat skew distributions. Say one of these 8 variables is X. I ask for H - hist(X,breaks=50), and get a histogram which usually has a different number of cells than what I intended. For instance, for one of these simulations, the 8 different values of length(H$breaks) are: 70, 44, 38, 68, 50, 40, 46, 45 ?hist tells me A) breaks: one of: * a vector giving the breakpoints between histogram cells, * a single number giving the number of cells for the histogram, * a character string naming an algorithm to compute the number of cells (see Details), * a function to compute the number of cells. In the last three cases the number is a suggestion only. B) The default for 'breaks' is 'Sturges': see 'nclass.Sturges'. If I look at the code for nclass.Sturges() I see function (x) ceiling(log2(length(x)) + 1) and, for length(X) = 1, this gives 15. This is not related to any of the numbers of breaks I actually got, in any way obvious to me. So: Question 1: hist() has apparently ignored my suggestion of break=50. Why? What is the criterion for ignoring? Question 2: Presumably, if it ignores the suggestion, it does something else, of its choice. I would then, perhaps, expect it to fall back to its default, which is (allegedly) Sturges. But the result from nclass.Sturges looks different from what it actually did. So what did it actually do, and how did it decide on this? No, it is not ignoring you. Try hist(rnorm(1)) length(hist(rnorm(1),breaks=50)$breaks) and repeat a dozen of times or so. Chances are that you'll mostly see lengths around 40, but definitely more than the 17 or so that you'll see without the breaks=50. Next, try diff(hist(rnorm(1),breaks=50)$breaks) and notice that this is usually 0.2, although if you repeat enough times, you might get a couple of cases with 0.1 and a length of 75(-ish). Get it? Otherwise look at help(pretty) since this is what is doing the work. -p With thanks, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 19-May-08 Time: 10:31:20 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Startin R from .RData in linux
On 05/19/08 09:06, Agustin Lobo wrote: Hi! Is it possible to start R by clicking the .RData file in linux as in Windows? I've tried with ubuntu hardy using the right button and selecting R, but does not work. Is there any way to set it up? You presumably need to associate the file type .RData with starting a terminal and then executing R in that terminal. I'm using Xubuntu, so my file manager is Thunar, and if I right click on an .RData and select use other application then custom command, then put in xfterm4 -e R this works. On Ubuntu, your terminal is probably something else and may have different syntax. (gnome-terminal maybe? then man gnome-terminal in case the -e option doesn't work for you). m. -- Marianne Promberger Graduate student in Psychology http://www.psych.upenn.edu/~mpromber __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How hist() decides breaks?
On 19-May-08 10:00:10, Peter Dalgaard wrote: (Ted Harding) wrote: Hi Folks, I'd like to know how hist() decides how many cells to use when it ignores my suggestion to use say 'hist(...,breaks=50)'. More specifically, I have the results of 1 simulations, each returning an 8-vector, therefore 8 variables each with 1 values. Some of these 8 have somewhat skew distributions. Say one of these 8 variables is X. I ask for H - hist(X,breaks=50), and get a histogram which usually has a different number of cells than what I intended. For instance, for one of these simulations, the 8 different values of length(H$breaks) are: 70, 44, 38, 68, 50, 40, 46, 45 ?hist tells me A) breaks: one of: * a vector giving the breakpoints between histogram cells, * a single number giving the number of cells for the histogram, * a character string naming an algorithm to compute the number of cells (see Details), * a function to compute the number of cells. In the last three cases the number is a suggestion only. B) The default for 'breaks' is 'Sturges': see 'nclass.Sturges'. If I look at the code for nclass.Sturges() I see function (x) ceiling(log2(length(x)) + 1) and, for length(X) = 1, this gives 15. This is not related to any of the numbers of breaks I actually got, in any way obvious to me. So: Question 1: hist() has apparently ignored my suggestion of break=50. Why? What is the criterion for ignoring? Question 2: Presumably, if it ignores the suggestion, it does something else, of its choice. I would then, perhaps, expect it to fall back to its default, which is (allegedly) Sturges. But the result from nclass.Sturges looks different from what it actually did. So what did it actually do, and how did it decide on this? No, it is not ignoring you. Try hist(rnorm(1)) length(hist(rnorm(1),breaks=50)$breaks) and repeat a dozen of times or so. Chances are that you'll mostly see lengths around 40, but definitely more than the 17 or so that you'll see without the breaks=50. Next, try diff(hist(rnorm(1),breaks=50)$breaks) and notice that this is usually 0.2, although if you repeat enough times, you might get a couple of cases with 0.1 and a length of 75(-ish). Get it? Otherwise look at help(pretty) since this is what is doing the work. -p Thanks for the pointer to 'pretty', whose role is not mentioned in ?hist. I shall study this! (I still don't get it!) In your example above I generally get 38-40 breaks (with 50 requested), but once (in about 30 repetitions) I got 72, as you point out. I then tried it with 1.1*rnorm(1), and got 42-51; then with 1.2*rnorm(1), and got 46-51; then with 1.3*rnorm(1), and got 47-61. It seems there is a slightly unstable relationship between the urge to honour the requested n=50, and the desire to achieve nice numerical values (on the scale of 10) for the values of the breakpoints. Thanks. Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 19-May-08 Time: 12:00:28 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Sort matrix with duplicate row names alphabetically by rowname
Hi, I've a matrix that contains 4 replicates of each rowname. (4 a's, 4 b's, 4 c's in no particular order) Like this: # c 32 a 1 b 4 c 87 c 34 b 54 a 23 a 12 b 9 a 3 b 87 c 43 There are a couple of more columns but I'm using the above as an example I need to sort it so that the same rownames appear together in alpahbetical order. Like this: # a 1 a 23 a 12 a 3 b 4 b 54 b 9 b 87 c 87 c 34 c 43 c 32 The code I came up with is something like this: mat - mat[sort(rownames(mat)), ] This doesn't work though, it returns the same value for each row each time, something like this: # a 1 a 1 a 1 a 1 b 4 b 4 b 4 b 4 c 32 c 32 c 32 c 32 Any ideas how I could get my code to distinguish between the different rows and get the output I'm looking for? Thanks, -Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sort matrix with duplicate row names alphabetically by rowname
Try: mat - mat[order(rownames(mat)), ] --- -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Geeleher Sent: 19 May 2008 12:07 To: r-help@r-project.org Subject: [R] Sort matrix with duplicate row names alphabetically by rowname Hi, I've a matrix that contains 4 replicates of each rowname. (4 a's, 4 b's, 4 c's in no particular order) Like this: # c 32 a 1 b 4 c 87 c 34 b 54 a 23 a 12 b 9 a 3 b 87 c 43 There are a couple of more columns but I'm using the above as an example I need to sort it so that the same rownames appear together in alpahbetical order. Like this: # a 1 a 23 a 12 a 3 b 4 b 54 b 9 b 87 c 87 c 34 c 43 c 32 The code I came up with is something like this: mat - mat[sort(rownames(mat)), ] This doesn't work though, it returns the same value for each row each time, something like this: # a 1 a 1 a 1 a 1 b 4 b 4 b 4 b 4 c 32 c 32 c 32 c 32 Any ideas how I could get my code to distinguish between the different rows and get the output I'm looking for? Thanks, -Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] From strings to numbers
Dear all, I would like to know if there is an easy to transform a vector of strings to a vector of integers. Ex: (ab,ab,bb,cat,cat,ab) will be (1, 1, 2, 3, 3, 1) Thx, Naira -- View this message in context: http://www.nabble.com/From-strings-to-numbers-tp17315179p17315179.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RExcel - foreground server
Hi, I have a problem using RExcel with a foreground server: in RExcel menu as well as in the window called by set server the foreground server option is grayed out. I have installed the rcom package and also tried to open R and type require(rcom), as explained on http://sunsite.univie.ac.at/rcom/excel/index.html, but it does not help. What am I missing? Many thanks, Werner __ Dem pfiffigeren Posteingang. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sort matrix with duplicate row names alphabetically by rowname
Ah, job done, that was simple! Thanks, -Paul. On Mon, May 19, 2008 at 12:24 PM, john seers (IFR) [EMAIL PROTECTED] wrote: Try: mat - mat[order(rownames(mat)), ] --- -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Paul Geeleher Sent: 19 May 2008 12:07 To: r-help@r-project.org Subject: [R] Sort matrix with duplicate row names alphabetically by rowname Hi, I've a matrix that contains 4 replicates of each rowname. (4 a's, 4 b's, 4 c's in no particular order) Like this: # c 32 a 1 b 4 c 87 c 34 b 54 a 23 a 12 b 9 a 3 b 87 c 43 There are a couple of more columns but I'm using the above as an example I need to sort it so that the same rownames appear together in alpahbetical order. Like this: # a 1 a 23 a 12 a 3 b 4 b 54 b 9 b 87 c 87 c 34 c 43 c 32 The code I came up with is something like this: mat - mat[sort(rownames(mat)), ] This doesn't work though, it returns the same value for each row each time, something like this: # a 1 a 1 a 1 a 1 b 4 b 4 b 4 b 4 c 32 c 32 c 32 c 32 Any ideas how I could get my code to distinguish between the different rows and get the output I'm looking for? Thanks, -Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] From strings to numbers
On 5/19/2008 6:13 AM, Naira wrote: Dear all, I would like to know if there is an easy to transform a vector of strings to a vector of integers. Ex: (ab,ab,bb,cat,cat,ab) will be (1, 1, 2, 3, 3, 1) X - c(ab,ab,bb,cat,cat,ab) as.numeric(as.factor(X)) [1] 1 1 2 3 3 1 Thx, Naira -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] From strings to numbers
Naira wrote: Dear all, I would like to know if there is an easy to transform a vector of strings to a vector of integers. Ex: (ab,ab,bb,cat,cat,ab) will be (1, 1, 2, 3, 3, 1) Hi Naira, It's not all that hard... newfactor-as.factor(c(ab,ab,bb,cat,cat,ab)) newfactor [1] ab ab bb cat cat ab Levels: ab bb cat as.numeric(newfactor) [1] 1 1 2 3 3 1 Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: Sort matrix with duplicate row names alphabetically by rowname
Hi [EMAIL PROTECTED] napsal dne 19.05.2008 13:06:33: Hi, I've a matrix that contains 4 replicates of each rowname. (4 a's, 4 b's, 4 c's in no particular order) Like this: # c 32 a 1 b 4 c 87 c 34 b 54 a 23 a 12 b 9 a 3 b 87 c 43 There are a couple of more columns but I'm using the above as an example I need to sort it so that the same rownames appear together in alpahbetical order. Like this: # a 1 a 23 a 12 a 3 b 4 b 54 b 9 b 87 c 87 c 34 c 43 c 32 The code I came up with is something like this: mat - mat[sort(rownames(mat)), ] Quite close mat - mat[order(rownames(mat)), ] Regards Petr This doesn't work though, it returns the same value for each row each time, something like this: # a 1 a 1 a 1 a 1 b 4 b 4 b 4 b 4 c 32 c 32 c 32 c 32 Any ideas how I could get my code to distinguish between the different rows and get the output I'm looking for? Thanks, -Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] From strings to numbers
Jim and Chuck, Thanks a lot for your replies :) I knew that there was a better way than the complex thing I was planning to apply :p (with a lot of for/while/apply arghhh) I also remembered to use factor when my brain woke up ;) I did something like unclass(factor(c(ab,ab,bb,cat,cat,ab))) which is also doing the right job. Thx a lot for your fast replies. Naira Jim Lemon wrote: Naira wrote: Dear all, I would like to know if there is an easy to transform a vector of strings to a vector of integers. Ex: (ab,ab,bb,cat,cat,ab) will be (1, 1, 2, 3, 3, 1) Hi Naira, It's not all that hard... newfactor-as.factor(c(ab,ab,bb,cat,cat,ab)) newfactor [1] ab ab bb cat cat ab Levels: ab bb cat as.numeric(newfactor) [1] 1 1 2 3 3 1 Jim -- == Naira Naouar Tel:+32 (0)9 331 38 63 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM [EMAIL PROTECTED] http://www.psb.ugent.be __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Rank Values in a Matrix
Dear All, a short and maybe simple question: I have to rank all values in a matrix from 0 to X, [1] [2] [3] [4] [1] 0.1 2 03 [2] 50 3 31 [3] 100 1 10 [4] 100 2 20 0-0 0.1-1 2-2 3-3 50-4 100-5 (X=5) is there any function for this? i have looked in several packages (vegan, labdsv etc.) because I am working with species by site tables, but without success. perhaps I looked for the wrong terms (rank matrix etc.) thank you for your help regards, Jens -- + Dipl.Biol. Jens Oldeland University of Hamburg Biocentre Klein Flottbek and Botanical Garden Ohnhorststr. 18 22609 Hamburg, Germany Tel:0049-(0)40-42816-407 Fax:0049-(0)40-42816-543 Mail: [EMAIL PROTECTED] [EMAIL PROTECTED] (for attachments 2mb!!) http://www.biologie.uni-hamburg.de/bzf/fbda005/fbda005.htm + __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R syntax, space smaller than space
Hi, I changed something in the package climatol especially in the function diagwl. Dos anybody know where I can put the code in the Internet to discuss it? I made from C for gradcelsius °C with: unit - list( temp = expression (paste(#T , degree,C)) ) mtext(unit$temp ,2,col=tcol,las=1,line=3,adj=0,at=55) mtext(paste(round(mean(tm*10))/10, ' °', C ,round(sum(p)), mm,sep=) But mtext(paste(round(mean(tm*10))/10, ' °', C ,round(sum(p)), mm,sep=) makes the ° and the C very short together. There is no space. How can I fill a space in there which is smaller as a normal space? Also I made more transparency in the colours with: sfcol= rgb(0, 0, 0,alpha =0.2) Is there a possibility to safe the diagram as *png (because of the transparancy) ? How can I made the line for the precipitation thicker? Thanks Torsten -- Torsten Wiebke Jabber: [EMAIL PROTECTED] [EMAIL PROTECTED] Yahoo: towieb __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rank Values in a Matrix
If your matrix below is called aa, you could do this matrix(rank(aa, ties='min'), ncol=ncol(aa)) [,1] [,2] [,3] [,4] [1,]481 11 [2,] 14 11 115 [3,] 15551 [4,] 15881 This doesn't assign the values you list, but it does rank them. OTOH, if you want as you have below, I think this works rank(unique(stack(aa)[1]))-1 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jens Oldeland Sent: Monday, May 19, 2008 7:47 AM To: [EMAIL PROTECTED] Subject: [R] Rank Values in a Matrix Dear All, a short and maybe simple question: I have to rank all values in a matrix from 0 to X, [1] [2] [3] [4] [1] 0.1 2 03 [2] 50 3 31 [3] 100 1 10 [4] 100 2 20 0-0 0.1-1 2-2 3-3 50-4 100-5 (X=5) is there any function for this? i have looked in several packages (vegan, labdsv etc.) because I am working with species by site tables, but without success. perhaps I looked for the wrong terms (rank matrix etc.) thank you for your help regards, Jens -- + Dipl.Biol. Jens Oldeland University of Hamburg Biocentre Klein Flottbek and Botanical Garden Ohnhorststr. 18 22609 Hamburg, Germany Tel:0049-(0)40-42816-407 Fax:0049-(0)40-42816-543 Mail: [EMAIL PROTECTED] [EMAIL PROTECTED] (for attachments 2mb!!) http://www.biologie.uni-hamburg.de/bzf/fbda005/fbda005.htm + __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rank Values in a Matrix
Hi Jens, If the matrix you described is m. Then, you can do unique(as.vector(m)) [1] 0.1 2.0 0.0 3.0 50.0 1.0 100.0 order(unique(as.vector(m))) [1] 3 1 6 2 4 5 7 Hope this helps :) Naira Jens Oldeland wrote: Dear All, a short and maybe simple question: I have to rank all values in a matrix from 0 to X, [1] [2] [3] [4] [1] 0.1 2 03 [2] 50 3 31 [3] 100 1 10 [4] 100 2 20 0-0 0.1-1 2-2 3-3 50-4 100-5 (X=5) is there any function for this? i have looked in several packages (vegan, labdsv etc.) because I am working with species by site tables, but without success. perhaps I looked for the wrong terms (rank matrix etc.) thank you for your help regards, Jens -- == Naira Naouar Tel:+32 (0)9 331 38 63 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM [EMAIL PROTECTED] http://www.psb.ugent.be __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rank Values in a Matrix
Whoops, I inadvertently created a dataframe called aa and not a matrix, so the code below assumes aa is a dataframe and not a matrix. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Doran, Harold Sent: Monday, May 19, 2008 8:15 AM To: Jens Oldeland; [EMAIL PROTECTED] Subject: Re: [R] Rank Values in a Matrix If your matrix below is called aa, you could do this matrix(rank(aa, ties='min'), ncol=ncol(aa)) [,1] [,2] [,3] [,4] [1,]481 11 [2,] 14 11 115 [3,] 15551 [4,] 15881 This doesn't assign the values you list, but it does rank them. OTOH, if you want as you have below, I think this works rank(unique(stack(aa)[1]))-1 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jens Oldeland Sent: Monday, May 19, 2008 7:47 AM To: [EMAIL PROTECTED] Subject: [R] Rank Values in a Matrix Dear All, a short and maybe simple question: I have to rank all values in a matrix from 0 to X, [1] [2] [3] [4] [1] 0.1 2 03 [2] 50 3 31 [3] 100 1 10 [4] 100 2 20 0-0 0.1-1 2-2 3-3 50-4 100-5 (X=5) is there any function for this? i have looked in several packages (vegan, labdsv etc.) because I am working with species by site tables, but without success. perhaps I looked for the wrong terms (rank matrix etc.) thank you for your help regards, Jens -- + Dipl.Biol. Jens Oldeland University of Hamburg Biocentre Klein Flottbek and Botanical Garden Ohnhorststr. 18 22609 Hamburg, Germany Tel:0049-(0)40-42816-407 Fax:0049-(0)40-42816-543 Mail: [EMAIL PROTECTED] [EMAIL PROTECTED] (for attachments 2mb!!) http://www.biologie.uni-hamburg.de/bzf/fbda005/fbda005.htm + __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] svIDE and Tinn-R
Probably an old moon since evoqued one year ago in this link: http://tolstoy.newcastle.edu.au/R/e2/help/07/04/15738.html but I have recently re-installed Tinn-R with R 2.7.0 and forgot to insert options(warn=-1) library(svIDE) ... options(warn=0) in Rprofile.site... and could see that we have still the same warning launching R: Warning messages: 1: '\A' is an unrecognized escape in a character string 2: unrecognized escape removed from ;for Options\AutoIndent: 0=Off, 1=follow language scoping and 2=copy from previous line\n 3: In grep(paste([{]TclEval , topic, [}], sep = ), tclvalue(.Tcl(dde services TclEval {})), : argument 'useBytes = TRUE' will be ignored I wonder how far it may be problematical ? Patrick __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] oligo ids
Dear list, I am having a set of human oligo ids (H26022 H22025 H34703 H20442 H25719 H300018350) which I want to map to Ensembl or RefSeq. I am sure R has a function to do that. I downloaded the {oligo} package and tried to use the probeNames function. Although the factor of ologo ids is an object (as the argument to probeNames should be) I retrieve the following error: probeNames(significant_genes[,1]) Error in function (classes, fdef, mtable) : unable to find an inherited method for function probeNames, for signature factor where significant_genes is the factor with the oligo ids. Could anyone help me with the format I should use in order to apply probeNames? Or if someone has any other function in mind whcih can do the mapping I would be really grateful to hear that. Thank you all, Eleni [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] From strings to numbers
On Mon, May 19, 2008 at 7:41 AM, Naira Naouar [EMAIL PROTECTED] wrote: Jim and Chuck, Thanks a lot for your replies :) I knew that there was a better way than the complex thing I was planning to apply :p (with a lot of for/while/apply arghhh) I also remembered to use factor when my brain woke up ;) I did something like unclass(factor(c(ab,ab,bb,cat,cat,ab))) which is also doing the right job. The responses you got do not depend on the internal representation of factors but using unclass does depend on that. Thx a lot for your fast replies. Naira Jim Lemon wrote: Naira wrote: Dear all, I would like to know if there is an easy to transform a vector of strings to a vector of integers. Ex: (ab,ab,bb,cat,cat,ab) will be (1, 1, 2, 3, 3, 1) Hi Naira, It's not all that hard... newfactor-as.factor(c(ab,ab,bb,cat,cat,ab)) newfactor [1] ab ab bb cat cat ab Levels: ab bb cat as.numeric(newfactor) [1] 1 1 2 3 3 1 Jim -- == Naira Naouar Tel:+32 (0)9 331 38 63 VIB Department of Plant Systems Biology, Ghent University Technologiepark 927, 9052 Gent, BELGIUM [EMAIL PROTECTED] http://www.psb.ugent.be __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Font settings in xfig
The main goal is to include graphics from R in a LaTeX document. Thanks a lot for all your help - its working now. /Robert On 16 Maj, 17:31, Greg Snow [EMAIL PROTECTED] wrote: If the main goal is to include graphs created by R in LaTeX documents and have them look nice, and usingxfigwas just one way of attempting this, then here are a couple other options that may or may not work better. Use the postscript graphics device and use psfrag in LaTeX to replace text in plot with LaTeX commands. This is fine if you are using postscript and only have a couple of things that need to be replaced. This can be a pain if you want to replace every tick mark label with the current font in the document, or if you want to go directly to pdf without going through postscript. Generate pdf/eps files of the graphs using the same font as your LaTeX document (see R-news article (6)2 41-47, on ways to specify the font). This changes the font to match, but does not do arbitrary LaTeX commands. Create an eps file, then use eps2pgf (http://sourceforge.net/projects/eps2pgf/) to convert to a pgf file to be included in your LaTeX file (via \input{}). You need to use the pgf package in your LaTeX file, but then all the graphics are done internally using by default the same fonts as the rest of the document. You can also do psfrag like replacements when converting the file to include LaTeX commands. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Scionforbai Sent: Friday, May 16, 2008 6:57 AM To: Kevin E. Thorpe Cc: [EMAIL PROTECTED]; Robert Subject: Re: [R] Font settings inxfig Is there a reason you are going through this route to get figures into LaTeX instead of using postscript (or PDF for pdflatex)? To have LaTeX-formatted text printed onto your pdf figures, to include in LaTeX documents. R cannot output 'special' text inxfig. You need to post-process the .fig file, according to the fig format (http://www.xfig.org/userman/fig-format.html), replacing, on lines starting with '4', the correct values for font and font_flags. Using awk (assuming you work on Linux) this is straightforward : awk '$1==4{$6=0;$9=2}{print}' R_FILE.fig OUT.fig Then, in order to obtain a pdf figure with LaTeX-formatted text, you need a simple driver.tex: driver.tex : \documentclass{article} \usepackage{epsfig} \usepackage{color} %(note: you might not might not need to do this) \begin{document} \pagestyle{empty} \input{FILE.pstex_t} \end{document} Now you can go through the compilation: fig2dev -L pstex OUT.fig OUT.pstex fig2dev -L pstex_t -p OUT.pstex OUT.fig OUT.pstex_t sed s/FILE/OUT/ driver.tex ./OUT.tex latex OUT.tex dvips -E OUT.dvi -o OUT.eps epstopdf OUT.eps Of course you need R to write the correct Latex math strings (like $\sigma^2$). Hope this helps, scionforbai __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [EMAIL PROTECTED] mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] three-dimensional (volumetric) estimation from x,y,z points
Hi people, sorry for this reposting. I sent it yesterday to the list, but as I don´t received a copy I suppose that occourred some problem. Kind regards, miltinho -- Forwarded message -- From: milton ruser [EMAIL PROTECTED] Date: May 18, 2008 10:35 PM Subject: three-dimensional (volumetric) estimation from x,y,z points To: R Help [EMAIL PROTECTED] Dear all, I have a set of x,y,z points obtained from a lizard species and now I would like to estimate the three-dimensional use of space for this species. I know that 2D area I can estimate using adehabitat packages, but I don´t know how to estimate the volumetric space. Any help are welcome. Miltinho Brazil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] oligo ids
Eleni Christodoulou elenichri at gmail.com writes: Dear list, I am having a set of human oligo ids (H26022 H22025 H34703 H20442 H25719 H300018350) which I want to map to Ensembl or RefSeq. [snip snip snip] I think you're more likely to get an answer to this question on the BioConductor help list than on the general R list -- most of the people here won't really know what you're talking about (I have a decent idea but don't know the answer to your question) -- Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] labels in multiple plot
My code is the following: point_type-c(black,gray20,red) ... for (i in 1:dim(m)[1]) { par(pch=(18+i)) par(fg=point_type[i]) plot(m[i,], type='b', ylim = c(lower, upper), type = l, ...) par(new=T) } Now I need to add an 'explanation' to each pch. I would have a box in the upperright corner of the plot containing several rows each one in the format: 'pch symbol': 'explanation' How can I do that? Thanx Bruno __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Least Squares Restricted Estimator
It is there any implementation of a Least Squares Restricted Estimator for a single equation in R? I have seen in the list some examples in which linear constraints are embedded within the equation, but let's say that I have a large number of coefficients (on factors) that I want them to sum up to 0 (so I can include an intercept, the full set of factors, and avoid the dummy trap). Is there any way to impose the restrictions in some matrix fashion (i.e. Rb = q)? Thanks, Nelson Villoria [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Log or diary file
The R2HTML package has tools for creating an HTML log of your session (see ?HTMLStart). Or the TeachingDemos package has a text based set of tools (see ?txtStart) for creating a log of your session. Neither is perfect (and imperfect in different ways), but could be what you are looking for. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Agustin Lobo Sent: Monday, May 19, 2008 1:24 AM To: r-help@r-project.org Subject: [R] Log or diary file Hi! Is it possible to set a file to which both commands and output would get automatically saved? I've tried with sink(), but only get the output. I mean something like a combined history and sink, as you get with File/Save to File.. in the windows GUI. Tis is done with diary filename in Matlab, and you can state diary on and diary off to control what is being saved to the file. Thanks Agus -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) LLuis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 email: [EMAIL PROTECTED] http://www.ija.csic.es/gt/obster __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] svIDE and Tinn-R
Hello, This does not seem to be something in the svIDE package, but something send by Tinn-R to R through the DDE connection for the first two warnings. I'll eliminate the last one for next version of the package. Best, Philippe Grosjean Patrick Giraudoux wrote: Probably an old moon since evoqued one year ago in this link: http://tolstoy.newcastle.edu.au/R/e2/help/07/04/15738.html but I have recently re-installed Tinn-R with R 2.7.0 and forgot to insert options(warn=-1) library(svIDE) ... options(warn=0) in Rprofile.site... and could see that we have still the same warning launching R: Warning messages: 1: '\A' is an unrecognized escape in a character string 2: unrecognized escape removed from ;for Options\AutoIndent: 0=Off, 1=follow language scoping and 2=copy from previous line\n 3: In grep(paste([{]TclEval , topic, [}], sep = ), tclvalue(.Tcl(dde services TclEval {})), : argument 'useBytes = TRUE' will be ignored I wonder how far it may be problematical ? Patrick __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Log or diary file
Agustin, Given this message and your previous one about starting R by clicking on the .RData file, I would suggest/recommend you have a look at the Emacs + ESS combination; see http://cran.r-project.org/doc/FAQ/R-FAQ.html#R-and-Emacs In my opinion, this is the best multi-platform (Unix, MacOS, Windows) user interface you will find for R. HTH Vincent Le lun. 19 mai à 03:24, Agustin Lobo a écrit : Hi! Is it possible to set a file to which both commands and output would get automatically saved? I've tried with sink(), but only get the output. I mean something like a combined history and sink, as you get with File/Save to File.. in the windows GUI. Tis is done with diary filename in Matlab, and you can state diary on and diary off to control what is being saved to the file. Thanks Agus -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) LLuis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 email: [EMAIL PROTECTED] http://www.ija.csic.es/gt/obster __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] labels in multiple plot
It is not clear what exactly you are trying to do, but you may want to look at ?matplot for an alternative to your loop, then look at ?legend for adding explanations. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bruno C. Sent: Monday, May 19, 2008 9:21 AM To: deepayan.sarkar Cc: price_ja; r-help Subject: [R] labels in multiple plot My code is the following: point_type-c(black,gray20,red) ... for (i in 1:dim(m)[1]) { par(pch=(18+i)) par(fg=point_type[i]) plot(m[i,], type='b', ylim = c(lower, upper), type = l, ...) par(new=T) } Now I need to add an 'explanation' to each pch. I would have a box in the upperright corner of the plot containing several rows each one in the format: 'pch symbol': 'explanation' How can I do that? Thanx Bruno __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [BioC] oligo ids
Thanks Sean! Your reply was very helpful. I already got almost what I wanted. I have some NA values but I will look if I can find them through bibliography or an external tool. Best Regards, Eleni On Mon, May 19, 2008 at 6:07 PM, Sean Davis [EMAIL PROTECTED] wrote: On Mon, May 19, 2008 at 10:47 AM, Eleni Christodoulou [EMAIL PROTECTED] wrote: Dear list, I am having a set of human oligo ids (H26022 H22025 H34703 H20442 H25719 H300018350) which I want to map to Ensembl or RefSeq. I am sure R has a function to do that. I downloaded the {oligo} package and tried to use the probeNames function. Although the factor of ologo ids is an object (as the argument to probeNames should be) I retrieve the following error: probeNames(significant_genes[,1]) Error in function (classes, fdef, mtable) : unable to find an inherited method for function probeNames, for signature factor where significant_genes is the factor with the oligo ids. Could anyone help me with the format I should use in order to apply probeNames? Or if someone has any other function in mind which can do the mapping I would be really grateful to hear that. Hi, Eleni. The probeNames() function is not applicable here, unfortunately. You are asking a question related to annotating your array. Therefore, you need an annotation package. I think the IDs that you specified are Qiagen (Operon) IDs, so the place to look is in the annotation package associated with the Qiagen arrays: Assuming that you are using R 2.7.0 (you are, correct?), then you can do: source('http://bioconductor.org/biocLite.R') biocLite('hguqiagenv3.db') library(hguqiagenv3.db) mget(c('H26022','H22025'),hguqiagenenv3REFSEQ) The last command will return a list of mappings between those two oligo ids and RefSeq. Typing: hguqiagenv3() will tell you the other annotation sources available for your qiagen chip. Ensembl mappings are available, as are a bunch of other mappings. Let us know if you have more questions. Sean [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] constrOptim converging not to the optimal values
Dear helpers, I am using constrOptim to minimize a function subject to inequality constraint. It works well when the number of parameters to optimize is low (e.g. 4) but when they are more (e.g. 10) it does not produce the expected results. The function is minus the determinant of a binomial logit model with one explanatory variable. Calling xeta the vector of explanatory variables the function to be optimized is: negdet-function(xeta) { pi - exp(a + b* xeta)/(1+exp(a + b* xeta)) -( sum(pi*(1-pi))*sum(pi*(1-pi)*xeta^2) - sum(pi*(1-pi)*xeta)^2 ) } With a intercept and b parameter of xeta in a standard binomial logit, i.e. p(i) = exp(a + b * xeta(i)) / (1 + exp(a + b*xeta(i) ) . I assume each element of xeta bounded between 0 and 10 and, in order to obtain an unique solution, I give an order to the elements of xeta (i.e. xeta(1) xeta(2) ... xeta(N)). The solution should be to fix half of the elements of xeta to the values that make the probability pi = 0.18 and half of them to the values that make pi = 0.82. This maximizes the determinant. For xeta constituted by only few elements (e.g. 2 or 4) constrOptim works well, but when the number of elements increases (e.g. 10) the procedure does not converge to the optimal values. Here is the code, with sample size = 4 and a = 5 and b= -2 the results are correct: $par [1] 3.272623 3.270943 1.727875 1.727867 $convergence [1] 0 But with sample size = 10, the optimization have problems: $par [1] 9.99 9.98 7.396835 3.281640 3.278376 3.277607 3.276871 1.737043 [9] 1.736261 1.732932 $convergence [1] 0 I would be extremely grateful if anybody could point out a reason for this and in particular if you could suggest any other procedure I could use to solve this optimization problem. Thanks a lot for your kindness, Carlo The code is below. SAMPLE SIZE N - 4 a- 5 b- -2 negdet-function(xeta) { pi - exp(a + b* xeta)/(1+exp(a + b* xeta)) -( sum(pi*(1-pi))*sum(pi*(1-pi)*xeta^2) - sum(pi*(1-pi)*xeta)^2 ) } ### BOUNDS low - 0 high - 10 ### ### MATRIX REPRESENTAION OF THE CONSTRAINTS order-c(rep(c(1,-1,rep(0,times=N-1)),N-2),1,-1) u1 - matrix(order,ncol=N, nrow=N-1, byrow=TRUE) bounds - c(rep(c(1,-1,rep(0,times=N*2)),N-1),1,-1) u2 - matrix(bounds, ncol=N,nrow=N*2) u.s -rbind(u1,u2) c.s -c(rep(0,N-1),rep(c(low,-high),N)) OPTIMIZATION a-constrOptim(outer.iteration = 500, control = list(maxit=1), theta=(high-low)/(N+1)* N:1, f=negdet, ui = u.s, ci=c.s, method=Nelder-Mead) ** Carlo Fezzi Senior Research Associate Centre for Social Research on the Global Environment (CSERGE) Department of Environmental Sciences University of East Anglia Norwich (UK) NR2 7TJ Telephone: +44(0)1603 591408 Fax: +44(0)1603 593739 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] reshape a wide data frame from wide to a long format with metadata columns
Hello R users and developers, I have a general question about reshaping a wide data frame using the reshape command. I have a data frame consisting of 108 columns that I would like to convert to a long table and remove the metadata (embedded in the column names of the wide table) to new metadata columns in the long format. #example data frame. NOTE column names contain metadata:: mediacont.21.MC1A contains treatment=mediacont, time=21, rep=MC1A data1-data.frame(cbind(name=0:10, mediacont.21.MC1A=10:20,mediatreat.20.MD1A=30:40, treat.20.T2C=50:60,treat.20.T2A=70:80,condtp.20.C2A=90:100,condtp.20.C2B=100:110, mediacont.21.MC1B=120:130, mediacont.21.MC1B=130:140)) #example of reshape code that works, this creates a data frame with single metadata column and unique ID column. I could use this and create a loop to write metadata columns based on the metadata in the time column. However if I understand from reading the reshape command it can create new metadata columns based on the names of the columns in wide format. I used the . as a separator between metadata. data2- reshape(data1, idvar=name, direction=long, varying=c(names(data1[-1])), v.names=intensity, times=names(data1[-1]),sep=.) ## this code does not work, but I think I need something like this. data3- reshape(data1, idvar=name, direction=long, varying=c(names(data1[-1])),sep=., v.names=list(c(treat,time,rep, intensity))) Could someone please offer me some scripting advise on how to reshape the dataframe from wide into long format and split the metadata out of the column names. sep=. I am trying to create a table with a header like this name, treat, time, rep, original column name, intensity Thank you, Alan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Least Squares Restricted Estimator
Nelson: 1. Please read the posting guide: your question is practically unintelligible. You are far more likely to get a useful response if you follow its recommendations. 2. However, I'll make a stab. **If** what you mean is simply to be able to choose arbitrary contrasts to estimate in linear models see ?lm, ?contrasts, ?C -- it can already been done. You may also be interested in pp 146-149 (the section on Contrast Matrices)in VR's MASS Fourth Edition (a most useful book to have on your shelf, IMHO), which I believe may be exactly what you're looking for. The gregmisc package/bundle, among others, may also contain some useful functions for you to fit arbitrary contrasts, I think. Cheers, Bert Gunter Genentech -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Villoria, Nelson B Sent: Monday, May 19, 2008 8:25 AM To: r-help@r-project.org Subject: [R] Least Squares Restricted Estimator It is there any implementation of a Least Squares Restricted Estimator for a single equation in R? I have seen in the list some examples in which linear constraints are embedded within the equation, but let's say that I have a large number of coefficients (on factors) that I want them to sum up to 0 (so I can include an intercept, the full set of factors, and avoid the dummy trap). Is there any way to impose the restrictions in some matrix fashion (i.e. Rb = q)? Thanks, Nelson Villoria [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reshape a wide data frame from wide to a long format with metadata columns
Hi Alan, I have a general question about reshaping a wide data frame using the reshape command. I have a data frame consisting of 108 columns that I would like to convert to a long table and remove the metadata (embedded in the column names of the wide table) to new metadata columns in the long format. You could try using the reshape _package_ (http://had.co.nz/reshape) to do this: data1 - data.frame( name = 0:10, mediacont.21.MC1A = 10:20, mediatreat.20.MD1A = 30:40, treat.20.T2C = 50:60, treat.20.T2A = 70:80, condtp.20.C2A = 90:100, condtp.20.C2B = 100:110, mediacont.21.MC1B = 120:130 ) dm - melt(data1, id = name) head(dm) ids - colsplit(dm$variable, \\., c(treatment,time,rep)) dm - cbind(dm, ids) dm$variable - NULL dm$time - as.numeric(dm$time) It's then easy to reshape and aggregate as required: cast(dm, treatment ~ time, mean) cast(dm, ... ~ treatment) Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error in building library - R CMD build mypkg.
Hi, I am getting an error when I am trying to build a library in R for windows . I am using R 2.7.0 in windows. I am following the instructions listed in the R Help for package creation. require(stats) ## two functions and two data sets : f - function(x,y) x+y g - function(x,y) x-y d - data.frame(a=1, b=2) e - rnorm(1000) package.skeleton(list=c(f,g,d,e), name=mypkg) Then in the command prompt I executed the following command: R CMD build mypkg I am getting the following error : * checking for file 'mypkg/DESCRIPTION' ... OK * preparing 'mypkg': * checking DESCRIPTION meta-information ... ERROR During startup - Warning messages: 1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : ' there is no package called 'NULL in options(defaultPackages) was not found What is it that I am not doing right ? Thanks, Ajay. - AVIS : Ce courrier et ses pieces jointes sont destines a leur seul destinataire et peuvent contenir des informations confidentielles appartenant a bioMerieux. Si vous n'etes pas destinataire, vous etes informe que toute lecture, divulgation, ou reproduction de ce message et des pieces jointes est strictement interdite. Si vous avez recu ce message par erreur merci d'en prevenir l'expediteur et de le detruire, ainsi que ses pieces jointes. NOTICE: This message and attachments are intended only for the use of their addressee and may contain confidential information belonging to bioMerieux. If you are not the intended recipient, you are hereby notified that any reading, dissemination, distribution, or copying of this message, or any attachment, is strictly prohibited. If you have received this message in error, please notify the original sender immediately and delete this message, along with any attachments. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] RSQLite and undefined symbol:sqlite3_bind_in
Hi Maya, You might want to post emails about specialized bioconductor packages to the bioconductor mailing list. You can sign up for it here: http://www.bioconductor.org/docs/mailList.html Please post your question over there and also tell us: how did you install RSQLite? Did you use biocLite() for that as well or did you use another method? Marc Maya Bercovich wrote: Hi All, I tried to install AnnotationDBI like so: source(http://bioconductor.org/biocLite.R;) biocLite(AnnotationDbi) and got this error: Loading required package: RSQLite Error in dyn.load(file, ...) : unable to load shared library '/RHEL3/local/lib64/R/library/ RSQLite/libs/RSQLite.so': /RHEL3/local/lib64/R/library/RSQLite/libs/RSQLite.so: undefined symbol: sqlite3_bind_int Error: package 'RSQLite' could not be loaded Execution halted ERROR: lazy loading failed for package 'AnnotationDbi' ** Removing '/RHEL3/local/lib64/R/library/AnnotationDbi' The downloaded packages are in /RHEL3/tmp/Rtmp6ex1Pz/downloaded_packages Updating HTML index of packages in '.Library' Warning message: In install.packages(pkgs = pkgs, repos = repos, dependencies = dependencies, : installation of package 'AnnotationDbi' had non-zero exit status However, I did install RSQLite and the installation finished with no errors. But: require(RSQLite) Loading required package: RSQLite Error in dyn.load(file, ...) : unable to load shared library '/usr/local/lib64/R/library/RSQLite/ libs/RSQLite.so': /usr/local/lib64/R/library/RSQLite/libs/RSQLite.so: undefined symbol: sqlite3_bind_int The library and file do exist with 755 permissions. My session info: sessionInfo() R version 2.6.2 (2008-02-08) x86_64-unknown-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.U TF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF- 8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_ID ENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] DBI_0.2-4 loaded via a namespace (and not attached): [1] rcompgen_0.1-17 tools_2.6.2 Has anyone a clue? I am not a R user, just the IT person who has to install it, so if you need additional info from inside R, please let me know how to get it. Thanks a lot, Maya [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Re : three-dimensional (volumetric) estimation from x,y,z
You may use the geometry package and the convhulln function. This will allow you to compute the convex hull volume of a set of points in a n-dimensional space. -- Guilhaumon François Laboratoire Ecosystèmes Lagunaires UMR 5119 cc 93 Bat 24 Université Montpellier II 34 095 Montpellier France http://www.ecolag.univ-montp2.fr http://www.ecolag.univ-montp2.fr/software Tel : +33 4 67 14 45 71 Fax : +33 4 67 14 37 19 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how can i sort a column of data.frame ?
i have a data.frame with several columns that i want to sort one of them (one column) by descending order in such way that this sorting out recover all colums. what should i do? -- View this message in context: http://www.nabble.com/how-can-i-sort-a-column-of-data.frame---tp17324725p17324725.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how can i sort a column of data.frame ?
hanen hanen.mastouri at yahoo.fr writes: i have a data.frame with several columns that i want to sort one of them (one column) by descending order in such way that this sorting out recover all colums. what should i do? Maybe I missed something special you need, because I don't fully understand what recover all columns means. Try first with the description in the FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-sort-the-rows-of-a-data-frame_003f Dieter Menne __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how can i sort a column of data.frame ?
? order df-data.frame(a=rnorm(20),b=rpois(20,5),c=runif(20)) or-order(df$b,decreasing=T) df.or-df[or,] Weidong Gu Department of Medicine University of Alabama, Birmingham 1900 University Blvd., Birmingham, Alabama 35294 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of hanen Sent: Monday, May 19, 2008 1:11 PM To: r-help@r-project.org Subject: [R] how can i sort a column of data.frame ? i have a data.frame with several columns that i want to sort one of them (one column) by descending order in such way that this sorting out recover all colums. what should i do? -- View this message in context: http://www.nabble.com/how-can-i-sort-a-column-of-data.frame---tp17324725 p17324725.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question for Logic Regression
thanks for you response, i try predict command, it is doesn't work. i list a simulate code below: X - matrix(as.numeric(runif(400) 0.5), 50,8) colnames(X) - paste(X, 1:ncol(X), sep=) rownames(X) - paste(case, 1:nrow(X), sep=) # Define expected result: Y = (NOT X2) AND X6 Y - as.numeric(!X[,2] X[,6]) Z-cbin(X,Y) set.seed(12345) Annealing - logreg.anneal.control(start = 4, end = -4, iter = 1000, update = 50) logicfit - logreg(resp=Z[,9], bin=Z[,1:8], type = 3, select = 2, ntrees=2, nleaves=3, anneal.control=Annealing) new-data.frame(Z) new-NULL alltrees - predict(logicfit, new) names(logicfit) doesn't have coef class. thanks Yasir Kaheil wrote: try alltrees - predict(fit, model.dat2) # make sure response variable is not included in model.dat2 also to see the other attributes in fit, try: attributes(fit) thanks y coldeyes.Rhelp wrote: Hi All: how to get the coefficient for logic regression using selection=2 ( fit multiple models) and type=3 ( logistic regression) for example i have a fit like below : fit-logreg(resp = model.dat[,21], bin=model.dat[, 2:18],sep=model.dat[,1] ,type=3,select=2,ntrees=2,nleaves=6 ,anneal.control=Annealing,tree.control=TreeControl) i try to use fit$coef but i get nothing. and i try to use eval.logreg to evaluate a validate data model.dat2, but i cannot fit model class make below formula work alltrees - eval.logreg(fit$model , model.dat2) could anyone enlighten me a little. thanks leo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/question-for-Logic-Regression-tp17310610p17325671.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to get confidence interval and coefficient in Logic Regression
sorry to bother everyone. i have question to get the coefficient and confidence interval in Logic Regression with Logistic model. below i list the R code X - matrix(as.numeric(runif(400) 0.5), 50,8) colnames(X) - paste(X, 1:ncol(X), sep=) rownames(X) - paste(case, 1:nrow(X), sep=) # Define expected result: Y = (NOT X1) AND X5 Y - as.numeric(!X[,1] X[,5]) z-as.numeric(runif(50)) model.dat-cbind(X,z,Y) set.seed(12345) Annealing - logreg.anneal.control(start = 4, end = -4, iter = 1000, update = 50) logicfit - logreg(resp=model.dat[,10], bin=model.dat[,1:8],sep=model.dat[,9], type = 3, select = 2, ntrees=2, nleaves=3, anneal.control=Annealing) use names(logicfit) , i didn't see coef class. how to i get the coefficient of the model , especially for the additive effect. is there command i can calculate the sd so that i can have confidence interval. model.dat2-model.dat secondly i try to use alltrees - eval.logreg(logicfit , model.dat2) to score a new data set model.dat2. but this doesn't work. thanks for your help. leo [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heatmap on pre-established hclust output?
Try this: library(gplots) x - as.matrix(USArrests) hc - hclust(dist(USArrests), ave) dend1 - as.dendrogram(hc) heatmap.2(x, Rowv=dend1) -G On May 16, 2008, at 12:23PM , Jeremiah Rounds wrote: To: [EMAIL PROTECTED] From: [EMAIL PROTECTED] Date: Fri, 16 May 2008 17:55:26 +0200 Subject: [R] heatmap on pre- established hclust output? Hi, Can someone please guide me towards how to produce heatmap output from the output of hclust run prior to the actual heatmap call? I have some rather lengthy clustering going on and tweeking the visual output with heatmap recalculating the clustering every time is not feasible. Thanks, Joh I can't say that i have actually tackled this, but I have some experience with the functions you mentioned. Heatmap takes an hclustfun function parameter. You can create a custom clustering function. I don't believe there is a rule that says you have to do actual work in that function call. Look at just returning the results of your more complicated clustering in that call without actually doing the calculations. Jeremiah Rounds Graduate Student Utah State University __ [EMAIL PROTECTED] project.org mailing list https://stat.ethz.ch/mailman/listinfo/r- help PLEASE do read the posting guide http://www.R-project.org/ posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ E-mail for the greater good. Join the im Initiative from Microsoft. ood [[alternative HTML version deleted]] ATT4398153.txt Gregory R. Warnes, Ph.D. Associate Professor Center for Biodefence Immune Modeling and Department of Biostatistics and Computational Biology University of Rochester [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] i want to export a data.frame to file.xls
in order to export a data.frame to sheet.xls i try: write(df,file=file_name.xls) but when i open it a message appears: impossible to oppen this file. her format is unvalid knowen that i work with excel_2007 what is the solution ? -- View this message in context: http://www.nabble.com/i-want-to-export-a-data.frame-to-file.xls-tp17326119p17326119.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help on nested FOR loops
I am new to more radical programming in R. I am trying to write a nested 'for' loop to produce output that takes subscripts like: for i taking values 1,2,3,4,5 and j taking values 1,2,3 I want to output for a computation using the combination values of i and j a value x like this; i jx 1 1 x11 1 2 x12 1 3 x13 2 1 x21 2 2 x22 2 3 x23 3 1 x31 3 2 x32 3 3 x33 ... Need help urgently. Thanks. Philip A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] recoding data with loops
# I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to. # let's say I have six variables as listed below (I really # have hundreds, but a few will illustrate the point). # I want to generate my dataframe (mdf) # with the 6 variables X 100 values with rnorm(7). # How do I do this? I tried many variations on the following: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) for(i in 1:length(var_list)) {var_list[1] - rnorm(100)} mdf - data.frame(cbind(varlist[1:length(var_list)]) mdf # Then, I'd like to recode the variables that begin with the letter H. # I've tried many variations of the following, but to no avail: reverse_list - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_list - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_list)) {mdf[ ,e_reversed_list][[i]] - recode(mdf[ ,e_reverse_list][[i]], '5:99=NA; 1=4; 2=3; 3=2; 4=1; ', as.factor.result=FALSE) # I'm sure I have many deep misunderstandings about the R language, but # if I can get this much done, I think I'll be well on my way to understanding R # and how it works with loops and dataframes. # Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help on nested FOR loops
Try: paste(x, as.vector(t(outer(1:4, 1:3, FUN=paste, sep=))), sep=) or paste(x, apply(expand.grid(1:4, 1:3), 1, paste, collapse=), sep=) On Mon, May 19, 2008 at 4:40 PM, Philip Twumasi-Ankrah [EMAIL PROTECTED] wrote: I am new to more radical programming in R. I am trying to write a nested 'for' loop to produce output that takes subscripts like: for i taking values 1,2,3,4,5 and j taking values 1,2,3 I want to output for a computation using the combination values of i and j a value x like this; i jx 1 1 x11 1 2 x12 1 3 x13 2 1 x21 2 2 x22 2 3 x23 3 1 x31 3 2 x32 3 3 x33 ... Need help urgently. Thanks. Philip A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] labels in multiple plot
Yep sorry I need to use the legend command but am not so good at: Given this pseudo-code: point_type-c(black,gray20,red) ... for (i in 1:dim(m)[1]) { par(pch=(18+i)) par(fg=point_type[i]) plot(m[i,], type='b', ylim = c(lower, upper), type = l, ...) legend( , legend=rownames(m)[i] ,pch=(18+i) par(new=T) } I want a singlebox appear in the plot, containing the legend; each line of the legend contains the pch and a name Thanx It is not clear what exactly you are trying to do, but you may want to look at ?matplot for an alternative to your loop, then look at ?legend for adding explanations. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bruno C. Sent: Monday, May 19, 2008 9:21 AM To: deepayan.sarkar Cc: price_ja; r-help Subject: [R] labels in multiple plot My code is the following: point_type-c(black,gray20,red) ... for (i in 1:dim(m)[1]) { par(pch=(18+i)) par(fg=point_type[i]) plot(m[i,], type='b', ylim = c(lower, upper), type = l, ...) par(new=T) } Now I need to add an 'explanation' to each pch. I would have a box in the upperright corner of the plot containing several rows each one in the format: 'pch symbol': 'explanation' How can I do that? Thanx Bruno __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recoding data with loops
If you're serious, start by reading the docs, especially An Introduction to R. There are also other learning resources listed on CRAN. -- Bert gunter Genentech -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Donald Braman Sent: Monday, May 19, 2008 12:42 PM To: r-help@r-project.org Subject: [R] recoding data with loops # I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to. # let's say I have six variables as listed below (I really # have hundreds, but a few will illustrate the point). # I want to generate my dataframe (mdf) # with the 6 variables X 100 values with rnorm(7). # How do I do this? I tried many variations on the following: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) for(i in 1:length(var_list)) {var_list[1] - rnorm(100)} mdf - data.frame(cbind(varlist[1:length(var_list)]) mdf # Then, I'd like to recode the variables that begin with the letter H. # I've tried many variations of the following, but to no avail: reverse_list - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_list - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_list)) {mdf[ ,e_reversed_list][[i]] - recode(mdf[ ,e_reverse_list][[i]], '5:99=NA; 1=4; 2=3; 3=2; 4=1; ', as.factor.result=FALSE) # I'm sure I have many deep misunderstandings about the R language, but # if I can get this much done, I think I'll be well on my way to understanding R # and how it works with loops and dataframes. # Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recoding data with loops
Thanks for quick response! I have done. I have tried many configurations of the various examples given there, but the examples are pretty short and none explain how to loop through nonconsecutive variables in a data frame. I've also read dozens of pages that come up when I google data.frame rnorm and data.frame loops, but to no avail. On Mon, May 19, 2008 at 3:54 PM, Bert Gunter [EMAIL PROTECTED] wrote: If you're serious, start by reading the docs, especially An Introduction to R. There are also other learning resources listed on CRAN. -- Bert gunter Genentech -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Donald Braman Sent: Monday, May 19, 2008 12:42 PM To: r-help@r-project.org Subject: [R] recoding data with loops # I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to. # let's say I have six variables as listed below (I really # have hundreds, but a few will illustrate the point). # I want to generate my dataframe (mdf) # with the 6 variables X 100 values with rnorm(7). # How do I do this? I tried many variations on the following: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) for(i in 1:length(var_list)) {var_list[1] - rnorm(100)} mdf - data.frame(cbind(varlist[1:length(var_list)]) mdf # Then, I'd like to recode the variables that begin with the letter H. # I've tried many variations of the following, but to no avail: reverse_list - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_list - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_list)) {mdf[ ,e_reversed_list][[i]] - recode(mdf[ ,e_reverse_list][[i]], '5:99=NA; 1=4; 2=3; 3=2; 4=1; ', as.factor.result=FALSE) # I'm sure I have many deep misunderstandings about the R language, but # if I can get this much done, I think I'll be well on my way to understanding R # and how it works with loops and dataframes. # Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Donald Braman http://www.law.gwu.edu/Faculty/profile.aspx?id=10123 http://research.yale.edu/culturalcognition http://ssrn.com/author=286206 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] i want to export a data.frame to file.xls
Hi Hanen, Take a look at ?write.table. Also, try this: write.table(df,file_name.xls,col.names=FALSE,row.names=FALSE,sep=\t) or write.table(df,file_name.xls,sep=\t) HTH, Jorge On Mon, May 19, 2008 at 3:27 PM, hanen [EMAIL PROTECTED] wrote: in order to export a data.frame to sheet.xls i try: write(df,file=file_name.xls) but when i open it a message appears: impossible to oppen this file. her format is unvalid knowen that i work with excel_2007 what is the solution ? -- View this message in context: http://www.nabble.com/i-want-to-export-a-data.frame-to-file.xls-tp17326119p17326119.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] i want to export a data.frame to file.xls
hanen wrote: in order to export a data.frame to sheet.xls i try: write(df,file=file_name.xls) but when i open it a message appears: impossible to oppen this file. her format is unvalid knowen that i work with excel_2007 what is the solution ? Hi, write.csv(df,filename.csv) will save it in .csv format which is readable by excel. Can then be saved as .xls in excel OR ?write.xls (package: xlsReadWrite) Blay - Blay S KATH Kumasi, Ghana. -- View this message in context: http://www.nabble.com/i-want-to-export-a-data.frame-to-file.xls-tp17326119p17326619.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recoding data with loops
Hello - Donald Braman wrote: # I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to. # let's say I have six variables as listed below (I really # have hundreds, but a few will illustrate the point). # I want to generate my dataframe (mdf) # with the 6 variables X 100 values with rnorm(7). # How do I do this? I tried many variations on the following: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) for(i in 1:length(var_list)) {var_list[1] - rnorm(100)} mdf - data.frame(cbind(varlist[1:length(var_list)]) mdf There are many ways to do this. Do you mean that you want 6 columns, 100 observations in each column, each a sample from a normal distribution with mean = 7 and sd = 1? You can do this without looping in one of several ways. If you are coming from a SAS environment (my guess since you talk of looping over data.frames), you may be used to looping through a data object. In R, you can usually avoid this since many functions are vectorized, or take a 'whole object' approach. var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) mdf - data.frame(replicate(6, rnorm(100, 7))) ## generate random data names(mdf) ## default names names(mdf) - var_list ## use our names # Then, I'd like to recode the variables that begin with the letter H. # I've tried many variations of the following, but to no avail: reverse_list - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_list - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_list)) {mdf[ ,e_reversed_list][[i]] - recode(mdf[ ,e_reverse_list][[i]], '5:99=NA; 1=4; 2=3; 3=2; 4=1; ', as.factor.result=FALSE) I'm not quite sure what you are after here. What do you mean by recode? What package is your 'recode' function located in? It appears that you may be under the impression that the data.frame contains integers, but certainly it will not since it was generated with rnorm? sample can generate a samples of the type you may be after, for example, sample(7, 100, replace = TRUE) Best, Erik Iverson __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] Updated package adimpro
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 This package implements tools for manipulationg digital images and the Propagation Separation approach for smoothing digital images. Version 0.6.1 is a major update with many new features: Input/Output: - - we now keep exif information as comment of an image ~ this information is evaluated to recover the original adimpro-object ~ used to produce the image file, see demo(io). ~ This may be changed to using rpm-profiles. - - new function write.raw provides a possibility to store ~ RAW sensor data as a greyscale png-image ~ these images are recognized by read.raw, see demo(raw). - - write.image now keeps color space by default - - read.image/write.image now also handles xyz, yuv, yiq and ~ hsi color spaces correctly - - the location of ImageMagick is now automatically determined ~ using function Sys.which and set as an environment variable ~ ImageMagick when the package is loaded (This requires R =2.6.0). ~ The argument convert.path in read.image and write.image is no ~ longer needed and has been removed. - - make.image no longer has an argument gamma Adaptive smoothing: - - functions awsimage, awspimage: - - value of ladjust 1.0 -- 1.25, different lseq - - new arguments plateau=NULL, homogen=TRUE, earlystop=TRUE - - new varmodel Quadratic - - location kernel with choice Plateau - - statistical kernel changed to Plateau with spmin=0.25 - - FORTRAN subroutine awsimg has fewer parameters - - lseq extended (if it is to short) by last element rather than by 1 - - FORTRAN subroutine awsvimage has differing parameters - - FORTRAN subroutine mawsimg has fewer parameters - - FORTRAN subroutine awspimg has fewer parameters - - handles lower/uppercase for some arguments - - new function awsprop for testing propagation condition - - new function awsaniso for anisotropic structural adaptive smoothing Color space conversions: - - increased and changed functionality of adjust.image - - rgb2xxx also accepts colorspaces xyz , yuv and yiq - - xxx2rgb - functions now allow to specify RGB-color space (default ~ Adobe) - - new function cam2rgb for conversion of camera color spaces to RGB - - new funcions rgb2xyzmat and xyz2rgbmat - - function gamma.correction now uses gammatype instead of arguments ga ~ and bp - - new function for inverse gamma correction - - new function whitepoint, wpofT, changewhitepoint for white point ~ definitions and manipulation - - whitebalance no uses whitepoint and color temperature - - adjust.image now allows to set gammatype, cspace, whitep, color ~ temperature blackpoint and exposure - - new function demosaic.raw to convert RAW sensor data to RGB Image manipulations and diagnostics: - - function edges has a new argument abs - - functions shrink.image, rotate.image, clip.image also accept RAW - - rotate.image has new argument compress - - new function extract.info for extracting EXIF-Information Bug fixes: e.g. in make.image, invgamma.correction (internal), ~ read.ppm(internal), read.pgm(internal), Demos: We added an extensive set of demos. demo(adimpro) just runs all demos sequentially. Especially demo(awspimage) (local polynomial smoothing) is time consuming. - -- Karsten Tabelow, Dr. WIAS Berlin Mohrenstrasse 39, 10117 Berlin, Germany email: [EMAIL PROTECTED] phone: +49-30-20372 564 fax : +49-30-2044975 url : http://www.wias-berlin.de/people/tabelow/ url : http://www.wias-berlin.de/project-areas/stat/a3 Member of Matheon (www.matheon.de) D08D1822 8EC1 479A ECD6 18C1 5DD7 E63E 32F1 50A9 D08D 1822 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIMX/fMvFQqdCNGCIRAjQ1AJ9BkbKNO6hQnDj2p466KxWRGOQ9EgCZAUfX djO1KxHt9uogG9fNDSLtKUI= =pbts -END PGP SIGNATURE- ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] Updated package fmri
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 fmri is a contributed package for R, that implements functions for analyzing single-subject fmri data with structural adaptive smoothing methods. New in version 1.2-6 - ~ - new function cutroi() ~ - plot.fmridata() is now able to produce anatomical overlay for pvalue ~data for AFNI, and NIFTI data ~ - read.AFNI() should be able to interpret filenames more flexible: ~with, without extensions, with dots in name. - -- Karsten Tabelow, Dr. WIAS Berlin Mohrenstrasse 39, 10117 Berlin, Germany email: [EMAIL PROTECTED] phone: +49-30-20372 564 fax : +49-30-2044975 url : http://www.wias-berlin.de/people/tabelow/ url : http://www.wias-berlin.de/project-areas/stat/a3 Member of Matheon (www.matheon.de) D08D1822 8EC1 479A ECD6 18C1 5DD7 E63E 32F1 50A9 D08D 1822 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIMX/cMvFQqdCNGCIRAgfoAJ4hxwFLSTup4Zf8NYriVvzKiKbErwCfSIXI Vt0ggjbb7GEfCMJVhzkWeRQ= =IHty -END PGP SIGNATURE- ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] New package dti
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 dti is a new contributed package for R, that implements functions for smoothing Diffusion-weighted MR data with structural adaptive smoothing methods. Version 0.5-2 contains functions for smoothing DW data in the context of the Diffusion Tensor Model and for visualization of Diffusion Tensor Data and anisotropy maps derived thereof. The tensor estimation can be done using a linearized model, or using a non-linear model. A correction for Rician bias can be included. - -- Karsten Tabelow, Dr. WIAS Berlin Mohrenstrasse 39, 10117 Berlin, Germany email: [EMAIL PROTECTED] phone: +49-30-20372 564 fax : +49-30-2044975 url : http://www.wias-berlin.de/people/tabelow/ url : http://www.wias-berlin.de/project-areas/stat/a3 Member of Matheon (www.matheon.de) D08D1822 8EC1 479A ECD6 18C1 5DD7 E63E 32F1 50A9 D08D 1822 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIMX/aMvFQqdCNGCIRAt3gAKCCdv9f8h030EAFpzIWL8npiJCq/wCfXWYK IufrFV0vmO7Dcz/Rr2QzFGs= =HWa8 -END PGP SIGNATURE- ___ R-packages mailing list [EMAIL PROTECTED] https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recoding data with loops
Many thanks -- You are right; I had rnorm() and sample() mixed up in my code. I'll work on generating a normal ordinal sample next. Cheers, Don On Mon, May 19, 2008 at 4:07 PM, Erik Iverson [EMAIL PROTECTED] wrote: Hello - Donald Braman wrote: # I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to. # let's say I have six variables as listed below (I really # have hundreds, but a few will illustrate the point). # I want to generate my dataframe (mdf) # with the 6 variables X 100 values with rnorm(7). # How do I do this? I tried many variations on the following: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) for(i in 1:length(var_list)) {var_list[1] - rnorm(100)} mdf - data.frame(cbind(varlist[1:length(var_list)]) mdf There are many ways to do this. Do you mean that you want 6 columns, 100 observations in each column, each a sample from a normal distribution with mean = 7 and sd = 1? You can do this without looping in one of several ways. If you are coming from a SAS environment (my guess since you talk of looping over data.frames), you may be used to looping through a data object. In R, you can usually avoid this since many functions are vectorized, or take a 'whole object' approach. var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) mdf - data.frame(replicate(6, rnorm(100, 7))) ## generate random data names(mdf) ## default names names(mdf) - var_list ## use our names # Then, I'd like to recode the variables that begin with the letter H. # I've tried many variations of the following, but to no avail: reverse_list - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_list - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_list)) {mdf[ ,e_reversed_list][[i]] - recode(mdf[ ,e_reverse_list][[i]], '5:99=NA; 1=4; 2=3; 3=2; 4=1; ', as.factor.result=FALSE) I'm not quite sure what you are after here. What do you mean by recode? What package is your 'recode' function located in? It appears that you may be under the impression that the data.frame contains integers, but certainly it will not since it was generated with rnorm? sample can generate a samples of the type you may be after, for example, sample(7, 100, replace = TRUE) Best, Erik Iverson -- Donald Braman http://www.law.gwu.edu/Faculty/profile.aspx?id=10123 http://research.yale.edu/culturalcognition http://ssrn.com/author=286206 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Histograms without bars
Hello I'd like to plot a histogram of some data composed of real numbers. The bin width I'm using is ~ 0.01, which results in high values in the y axis, so that the area under each bar corresponds to the probability of the data in that range. Is is possible to plot points whose y coordinate correspond to that probability, instead of plotting the histogram bars? In other words, instead of having a bar of width 0.01 and height, say, 80, I'd like to have a single point at y = 0.8. I know I could use the values returned from hist() and calculate that manually, but maybe there's a better way to do that. I've been using prop.table() to plot these histograms for integer numbers, but now I need binning and I'm not sure what is the best way to proceed. Thanks in advance, Andre __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] labels in multiple plot
Try: m - matrix( rnorm(30, rep(c(10,12,15), 10)), nrow=3 ) matplot(y=t(m), pch= rep(19:21, 10), type='b', col=c('red','green','blue')) legend('bottomright', legend=c('ABC','DEF','GHI'), pch=19:21, + col=c('red','green','blue')) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: Bruno C. [mailto:[EMAIL PROTECTED] Sent: Monday, May 19, 2008 1:49 PM To: Greg Snow Cc: deepayan.sarkar; price_ja; r-help Subject: RE: [R] labels in multiple plot Yep sorry I need to use the legend command but am not so good at: Given this pseudo-code: point_type-c(black,gray20,red) ... for (i in 1:dim(m)[1]) { par(pch=(18+i)) par(fg=point_type[i]) plot(m[i,], type='b', ylim = c(lower, upper), type = l, ...) legend( , legend=rownames(m)[i] ,pch=(18+i) par(new=T) } I want a singlebox appear in the plot, containing the legend; each line of the legend contains the pch and a name Thanx It is not clear what exactly you are trying to do, but you may want to look at ?matplot for an alternative to your loop, then look at ?legend for adding explanations. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Bruno C. Sent: Monday, May 19, 2008 9:21 AM To: deepayan.sarkar Cc: price_ja; r-help Subject: [R] labels in multiple plot My code is the following: point_type-c(black,gray20,red) ... for (i in 1:dim(m)[1]) { par(pch=(18+i)) par(fg=point_type[i]) plot(m[i,], type='b', ylim = c(lower, upper), type = l, ...) par(new=T) } Now I need to add an 'explanation' to each pch. I would have a box in the upperright corner of the plot containing several rows each one in the format: 'pch symbol': 'explanation' How can I do that? Thanx Bruno __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] interactive rotatable 3d scatterplot
On 16/05/2008 6:43 PM, Ben Bolker wrote: francois Guilhaumon francoisguilhaumon at gmail.com writes: I am facing the same problem than Mark Kimpel with the rgl package : Running various 3D rendering I'm always faced with a static 3d plot, which does not rotate when I click and mouse over it. I'm running Ubuntu linux 7.10 with a 32bit processor, thus the problem is not arising from 64bit issues. François. Are you running Compiz (fancy desktop effects)? You have to go to Appearance/Visual Effects in the Preferences menu and set None, because Compiz conflicts with rgl in its use of OpenGL. If any Ubuntu user can follow up on this and determine if there's a way for rgl to do something differently to avoid this conflict, I'd appreciate it (and other Ubuntu users might too). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recoding data with loops
Erik, Your example was just what I needed to generate the data -- many, many thanks! The names() function was something I had not grasped fully. I now have this and it works very nicely: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) mdf - data.frame(replicate(length(var_list), sample(7,100, replace = TRUE))) ## generate random data names(mdf) ## default names names(mdf) - var_list ## use our names mdf I'm still trying to figure out how to recode (using the car package) data into new variables using a similar loop. Basically, I'm not sure how to call the variable name and append it to the dataframe name in a loop. In Stata I'd do this using single quotes, but clearly that's not how R works. I tried several variations on this: reverse_me_varnames - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_varnames - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_me_varnames)) {mdf$reversed_varnames[i] - recode(mdf$reverse_me_varnames[i], '5:7=NA; 1=4; 2=3; 3=2; 4=1;', as.factor.result=FALSE) While I don't get an error message, the data don't change. Any advice on reverse coding non-continguous variables? On Mon, May 19, 2008 at 4:12 PM, Donald Braman [EMAIL PROTECTED] wrote: Many thanks -- You are right; I had rnorm() and sample() mixed up in my code. I'll work on generating a normal ordinal sample next. Cheers, Don On Mon, May 19, 2008 at 4:07 PM, Erik Iverson [EMAIL PROTECTED] wrote: Hello - Donald Braman wrote: # I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to. # let's say I have six variables as listed below (I really # have hundreds, but a few will illustrate the point). # I want to generate my dataframe (mdf) # with the 6 variables X 100 values with rnorm(7). # How do I do this? I tried many variations on the following: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) for(i in 1:length(var_list)) {var_list[1] - rnorm(100)} mdf - data.frame(cbind(varlist[1:length(var_list)]) mdf There are many ways to do this. Do you mean that you want 6 columns, 100 observations in each column, each a sample from a normal distribution with mean = 7 and sd = 1? You can do this without looping in one of several ways. If you are coming from a SAS environment (my guess since you talk of looping over data.frames), you may be used to looping through a data object. In R, you can usually avoid this since many functions are vectorized, or take a 'whole object' approach. var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) mdf - data.frame(replicate(6, rnorm(100, 7))) ## generate random data names(mdf) ## default names names(mdf) - var_list ## use our names # Then, I'd like to recode the variables that begin with the letter H. # I've tried many variations of the following, but to no avail: reverse_list - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_list - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_list)) {mdf[ ,e_reversed_list][[i]] - recode(mdf[ ,e_reverse_list][[i]], '5:99=NA; 1=4; 2=3; 3=2; 4=1; ', as.factor.result=FALSE) I'm not quite sure what you are after here. What do you mean by recode? What package is your 'recode' function located in? It appears that you may be under the impression that the data.frame contains integers, but certainly it will not since it was generated with rnorm? sample can generate a samples of the type you may be after, for example, sample(7, 100, replace = TRUE) Best, Erik Iverson -- Donald Braman http://www.law.gwu.edu/Faculty/profile.aspx?id=10123 http://research.yale.edu/culturalcognition http://ssrn.com/author=286206 -- Donald Braman http://www.law.gwu.edu/Faculty/profile.aspx?id=10123 http://research.yale.edu/culturalcognition http://ssrn.com/author=286206 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question for Logic Regression
try: alltrees - predict(logicfit) coldeyes wrote: thanks for you response, i try predict command, it is doesn't work. i list a simulate code below: X - matrix(as.numeric(runif(400) 0.5), 50,8) colnames(X) - paste(X, 1:ncol(X), sep=) rownames(X) - paste(case, 1:nrow(X), sep=) # Define expected result: Y = (NOT X2) AND X6 Y - as.numeric(!X[,2] X[,6]) Z-cbin(X,Y) set.seed(12345) Annealing - logreg.anneal.control(start = 4, end = -4, iter = 1000, update = 50) logicfit - logreg(resp=Z[,9], bin=Z[,1:8], type = 3, select = 2, ntrees=2, nleaves=3, anneal.control=Annealing) new-data.frame(Z) new-NULL alltrees - predict(logicfit, new) names(logicfit) doesn't have coef class. thanks Yasir Kaheil wrote: try alltrees - predict(fit, model.dat2) # make sure response variable is not included in model.dat2 also to see the other attributes in fit, try: attributes(fit) thanks y coldeyes.Rhelp wrote: Hi All: how to get the coefficient for logic regression using selection=2 ( fit multiple models) and type=3 ( logistic regression) for example i have a fit like below : fit-logreg(resp = model.dat[,21], bin=model.dat[, 2:18],sep=model.dat[,1] ,type=3,select=2,ntrees=2,nleaves=6 ,anneal.control=Annealing,tree.control=TreeControl) i try to use fit$coef but i get nothing. and i try to use eval.logreg to evaluate a validate data model.dat2, but i cannot fit model class make below formula work alltrees - eval.logreg(fit$model , model.dat2) could anyone enlighten me a little. thanks leo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Yasir H. Kaheil Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/question-for-Logic-Regression-tp17310610p17328322.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R is a virus, spyware or malware (gasp!)
And the installed Rgui.exe in 2.6.2 is 10240 bytes, which is their most common file size. They also say (fill in your own comments...): RGUI.EXE has been seen to perform the following behavior(s): * Can communicate with other computer systems using HTTP protocols * This Process Creates Other Processes On Disk * This Process Deletes Other Processes From Disk * Executes a Process * The Process is packed and/or encrypted using a software packing process * Accesses the MS Outlook Address Book and What you should do about RGUI.EXE: Check Your PC Now The most common objects with the name of RGUI.EXE have yet to be classified as safe by our research department. So, I suspect that they don't actually classify it as a virus, they just haven't classified it as safe... (I couldn't see any email contact address on their web page.) -- Tony Plate Peter Dalgaard wrote: Ioannis Dimakos wrote: Of course it's a virus. Once you catch the virus, you feel this rush, this fever to abandon all other statistical packages. On a more serious note, though, the size of the RGUI.exe file as reported in the webpage is not even near close to the actual size of the R distribution exe pack. Hmm, the installed Rgui.exe in 2.7.0rc (which is all I have, under Wine on a Fedora machine) appears to be 27648 bytes, which is one of the cited numbers. Presumably something needs to be done... I On Sun, May 18, 2008 17:30, Philippe Grosjean wrote: After a search session in Google, I found this page: http://www.prevx.com/filenames/X1993788672854780728-0/RGUI.EXE.html which classifies Rgui.exe (clearly stated as R for Windows GUI front-end) in a database of virus, spyware and malware! No comments! Philippe Grosjean __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Draw Polygon with a Circular Side
Hello Friends!!! I would want draw a circular histogram, and I would like draw a polygon with a circular side. This is easy if I use the functions polygon and arc, but I want that the polygon with a circular side have background colour. The polygon created with function polygon can have background colour, but the surface created with function arc can´t have background colour. How I could create a polygon with a circular side that have background colour?? Thank you very much, A greetings Luismi -- View this message in context: http://www.nabble.com/Draw-Polygon-with-a-Circular-Side-tp17328921p17328921.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Histograms without bars
Hi Andre, On May 19, 2008, at 4:28 PM, Andre Nathan wrote: Hello I'd like to plot a histogram of some data composed of real numbers. The bin width I'm using is ~ 0.01, which results in high values in the y axis, so that the area under each bar corresponds to the probability of the data in that range. Is is possible to plot points whose y coordinate correspond to that probability, instead of plotting the histogram bars? In other words, instead of having a bar of width 0.01 and height, say, 80, I'd like to have a single point at y = 0.8. I know I could use the values returned from hist() and calculate that manually, but maybe there's a better way to do that. I've been using prop.table() to plot these histograms for integer numbers, but now I need binning and I'm not sure what is the best way to proceed. I would use ?cut to create a factor, followed with the usual prop.table (+ table) you have been using. Unless you didn't want to have control over the precise binning? Thanks in advance, Andre Haris Skiadas Department of Mathematics and Computer Science Hanover College __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R is a virus, spyware or malware (gasp!)
I looked at the home website and found a contact form which someone could use to inform the company of the error of their ways. http://www.prevx.com/contactus.asp I will leave it to those who may be better equipped to deal with any replies from the company to contact them. Dan Daniel Nordlund Bothell, WA USA -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tony Plate Sent: Monday, May 19, 2008 2:30 PM To: Peter Dalgaard Cc: R help forum; Philippe Grosjean Subject: Re: [R] R is a virus, spyware or malware (gasp!) And the installed Rgui.exe in 2.6.2 is 10240 bytes, which is their most common file size. They also say (fill in your own comments...): RGUI.EXE has been seen to perform the following behavior(s): * Can communicate with other computer systems using HTTP protocols * This Process Creates Other Processes On Disk * This Process Deletes Other Processes From Disk * Executes a Process * The Process is packed and/or encrypted using a software packing process * Accesses the MS Outlook Address Book and What you should do about RGUI.EXE: Check Your PC Now The most common objects with the name of RGUI.EXE have yet to be classified as safe by our research department. So, I suspect that they don't actually classify it as a virus, they just haven't classified it as safe... (I couldn't see any email contact address on their web page.) -- Tony Plate Peter Dalgaard wrote: Ioannis Dimakos wrote: Of course it's a virus. Once you catch the virus, you feel this rush, this fever to abandon all other statistical packages. On a more serious note, though, the size of the RGUI.exe file as reported in the webpage is not even near close to the actual size of the R distribution exe pack. Hmm, the installed Rgui.exe in 2.7.0rc (which is all I have, under Wine on a Fedora machine) appears to be 27648 bytes, which is one of the cited numbers. Presumably something needs to be done... I On Sun, May 18, 2008 17:30, Philippe Grosjean wrote: After a search session in Google, I found this page: http://www.prevx.com/filenames/X1993788672854780728-0/RGUI.EXE.html which classifies Rgui.exe (clearly stated as R for Windows GUI front-end) in a database of virus, spyware and malware! No comments! Philippe Grosjean __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help on nested FOR loops
Hey Philip, I'm not sure if I understand what your x11, x12, etc. are. You can combine the values of your two vectors using the expand.grid function. There is no need to do nester FOR loops: i=c(1,2,3,4,5) j=c(1,2,3) x=expand.grid(i,j) print (x) Var1 Var2 1 11 2 21 3 31 4 41 5 51 6 12 7 22 8 32 9 42 1052 1113 1223 1333 1443 1553 Hope this helps, Julian Philip Twumasi-Ankrah wrote: I am new to more radical programming in R. I am trying to write a nested 'for' loop to produce output that takes subscripts like: for i taking values 1,2,3,4,5 and j taking values 1,2,3 I want to output for a computation using the combination values of i and j a value x like this; i jx 1 1 x11 1 2 x12 1 3 x13 2 1 x21 2 2 x22 2 3 x23 3 1 x31 3 2 x32 3 3 x33 ... Need help urgently. Thanks. Philip A Smile costs Nothing But Rewards Everything Happiness is not perfected until it is shared -Jane Porter [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R static is dynamically linked!!
Hi, After doing all I could find with the confiure script... I set some env too... export enable_R_static_lib=yes export want_R_static=yes export WANT_R_STATIC_TRUE=yes ./configure \ --prefix=${i} \ --enable-R-static-lib \ --enable-static \ --without-readline \ --without-iconv \ make \ make install \ echo R ${v} installed in ${i} But the result is still dynamic: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for NetBSD 4.0, dynamically linked (uses shared libs), not stripped Is there some way to make this static? // George -- George Georgalis, information system scientist IXOYE __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] useR! 2008: abstracts online
Dear useRs, we are happy to inform you that an overview of the presentations (including all abstracts) for the useR! 2008 conference in Dortmund (August 12-14) is now available online at http://www.R-project.org/useR-2008/presentations.html (A more detailed program will become available in the next weeks.) You can still register online for the regular fee until the end of this month (later registration is also possible): http://www.R-project.org/useR-2008/registration.html We would like to thank all useRs for submitting so many interesting abstracts and look forward to an exciting conference! The useR! organization team and program committee __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] 2.7.0 graphics changes and png devices
Hi, I have a question about the graphics changes in 2.7.0. The example is this bit of code: par(mfcol = c(2, 3)) for(i in 1:6) plot(1:10, 1:10, xlab = xlab, ylab = ylab, main = main) In 2.7.0, if I do this interactively (using windows()), I get bold titles. If I do this through a png device, I get regular weight titles. If I do this in 2.6.2, both situations give bold titles. I assume the 2.7.0 png device is off here, but I'm not sure how to fix this. Suggestions? Oliver __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 2.7.0 graphics changes and png devices
Apologies for the double-post, but I figured I should be slightly more specific. I'm using the windows version of 2.7.0 and 2.6.2. My calls to png is simply png(2.7.0.png) and png(2.6.2.png), respectively, followed by the appropriate dev.off(). Oliver On 5/19/08, Oliver Soong [EMAIL PROTECTED] wrote: Hi, I have a question about the graphics changes in 2.7.0. The example is this bit of code: par(mfcol = c(2, 3)) for(i in 1:6) plot(1:10, 1:10, xlab = xlab, ylab = ylab, main = main) In 2.7.0, if I do this interactively (using windows()), I get bold titles. If I do this through a png device, I get regular weight titles. If I do this in 2.6.2, both situations give bold titles. I assume the 2.7.0 png device is off here, but I'm not sure how to fix this. Suggestions? Oliver __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] boxplot subsets
Hello, I am a new user to R and have a(proabably very basic) question relating to a boxplot with eleven sites in a river system where i measured Chlorophyll a concentrations. The eleven sites are made up of three sites above a point source pollution site; three sites below this pollution source and five sites in a different unaffected river. The following code is for a simple plot of the data boxplot(Chl~Site,data=p,col=slategrey, boxwex=0.75,xlab=Site,ylim=c(0,250)) mtext(expression(Chlorophyll a (mg/m^2)),side=2,line=2.75,cex=0.7) The question is: 1) In my data sheet I have the sites grouped together (i.e. above pollution, below and unaffected), but the default setting in R seems to place these alphabetically on the x-axis rather than in the order I have entered into the spreadsheet. How to i correct this? Many thanks, Phil [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Need help in matrix multiplication error
Hi, I have a data file which is named test.txt as below. Prior to that, I have converted the last row from nominal to numeric using as.integer. Statement T1001 T1002 T1003 T1004 T1005 T100 T1014 T1021 T1022 T1023 1 0 0 0 0 0 00 0 1 0 0 20 0 0 0 0 00 0 1 0 0 3 0 1 0 0 1 00 0 1 0 0 4 406 pass pass fail pass pass pass pass pass pass pass After as.integer of pass, the below data is been transformed. Statement T1001 T1002 T1003 T1004 T1005 T100 T1014 T1021 T1022 T1023 1 0 0 0 0 0 00 0 1 0 0 20 0 0 0 0 00 0 1 0 0 3 0 1 0 0 1 00 0 1 0 0 4 0 1 1 0 11 1 1 1 1 1 The 1,2,3 and 4 on the first column is the automatic numbering seen on the terminal when i pasted here. And, i try to use matrix multiplication which is as.matrix(data[1:3,2:11])%*% sign(t(data[4,2:11])) Basically i wanted to count from column 2 onwards..which i want to ignore the Statement column data. Error in sign(t(data[4, 2:11])) : Non-numeric argument to mathematical function. I try take off the column constraint which is as.matrix(data[1:3,])%*% sign(t(data[4,])) but it still gives me Error in sign(t(data[4, ])) : Non-numeric argument to mathematical function I didnt understand how this error relate to my data above. Because my data is not a character at the first place and its a data.frame. Please help.Thanks.. Rgrds, Jason [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recoding data with loops
Got it, I did not know of the 'recode' function in car. So you would like to recode those specific columns then? Once again, we can do it without a loop, this time with the help of a function called lapply, which applies a function to each item in a list in turn. Try: reverse_me_varnames - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_varnames -paste(R, reverse_me_varnames, sep = ) ## See ?paste mdf[reversed_varnames] - lapply(mdf[reverse_me_varnames], function(x) recode(x, recodes = 5:7=NA; 1=4; 2=3; 3=2; 4=1;, as.factor.result = FALSE)) Now what does this actually mean? To the left of '-' is simply the new columns of our data.frame. We want to then use lapply to do some function to a list of objects. The first argument to lapply is that list. In this case, it is simply the columns of the data.frame you want reversed. A data.frame is a list in R. See ?list and ?data.frame. Then, the next argument to lapply is a function that we want to perform on each element in our list. So, we create a function that accepts as input a variable I simply call 'x'. This 'x' is going to be an item from the list we passed lapply, which is one of the columns of mdf in 'reverse_me_varnames'. We then use the recode function in the car package to recode x, in a similar way to what you tried before. This function of x we define will get called three times in the above example, once for each of reverse_me_varnames. It will then assign those three new columns to the left-hand side of the - operator, which are three newly-named columns. To see why what you tried before did not work, with the for loop, try: mdf$HEQUAL contrasted with t1 - c(HEQUAL) mdf$t1 From the help for ?Extract, $ does not allow 'computed' indices. I hope this helps! Erik Donald Braman wrote: Erik, Your example was just what I needed to generate the data -- many, many thanks! The names() function was something I had not grasped fully. I now have this and it works very nicely: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) mdf - data.frame(replicate(length(var_list), sample(7,100, replace = TRUE))) ## generate random data names(mdf) ## default names names(mdf) - var_list ## use our names mdf I'm still trying to figure out how to recode (using the car package) data into new variables using a similar loop. Basically, I'm not sure how to call the variable name and append it to the dataframe name in a loop. In Stata I'd do this using single quotes, but clearly that's not how R works. I tried several variations on this: reverse_me_varnames - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_varnames - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_me_varnames)) {mdf$reversed_varnames[i] - recode(mdf$reverse_me_varnames[i], '5:7=NA; 1=4; 2=3; 3=2; 4=1;', as.factor.result=FALSE) While I don't get an error message, the data don't change. Any advice on reverse coding non-continguous variables? On Mon, May 19, 2008 at 4:12 PM, Donald Braman [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Many thanks -- You are right; I had rnorm() and sample() mixed up in my code. I'll work on generating a normal ordinal sample next. Cheers, Don On Mon, May 19, 2008 at 4:07 PM, Erik Iverson [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hello - Donald Braman wrote: # I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to. # let's say I have six variables as listed below (I really # have hundreds, but a few will illustrate the point). # I want to generate my dataframe (mdf) # with the 6 variables X 100 values with rnorm(7). # How do I do this? I tried many variations on the following: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) for(i in 1:length(var_list)) {var_list[1] - rnorm(100)} mdf - data.frame(cbind(varlist[1:length(var_list)]) mdf There are many ways to do this. Do you mean that you want 6 columns, 100 observations in each column, each a sample from a normal distribution with mean = 7 and sd = 1? You can do this without looping in one of several ways. If you are coming from a SAS environment (my guess since you talk of looping over data.frames), you may be used to looping through a data object. In R, you can usually avoid this since many functions are vectorized, or take a 'whole object' approach. var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) mdf - data.frame(replicate(6,
Re: [R] Histograms without bars
Is is possible to plot points whose y coordinate correspond to that probability, instead of plotting the histogram bars? In other words, instead of having a bar of width 0.01 and height, say, 80, I'd like to have a single point at y = 0.8. Very easily with ggplot2: install.packages(ggplot2) library(ggplot2) qplot(carat, data=diamonds, stat=bin, geom=point) qplot(carat, data=diamonds, stat=bin, geom=point, binwidth=0.01) # or with a line qplot(carat, data=diamonds, stat=bin, geom=line) # oh and by default the y axis gives count, to give probalilites use qplot(carat, ..density.., data=diamonds, stat=bin, geom=point) Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R static is dynamically linked!!
On Mon 19 May 2008 at 06:39:39 PM -0400, George Georgalis wrote: Hi, After doing all I could find with the confiure script... I set some env too... export enable_R_static_lib=yes export want_R_static=yes export WANT_R_STATIC_TRUE=yes ./configure \ --prefix=${i} \ --enable-R-static-lib \ --enable-static \ --without-readline \ --without-iconv \ make \ make install \ echo R ${v} installed in ${i} But the result is still dynamic: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for NetBSD 4.0, dynamically linked (uses shared libs), not stripped Is there some way to make this static? In http://cran.r-project.org/doc/manuals/R-admin.html I did find: 9.1 Unix If R has not already be made in the directory tree, configure must tbe run as described in the main build instructions. Then make will make standalone libraries libRmath.a and libRmath.so. `make static' and make shared will create just one of them. however... make: don't know how to make static. Stop and static is not really part of the Makefile or any Make fragments. So back to starting... is there anyway to make it static? // George -- George Georgalis, information system scientist IXOYE __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] contr.treatments query
Hi Folks, I'm a bit puzzled by the following (example): N-factor(sample(c(1,2,3),1000,replace=TRUE)) unique(N) # [1] 3 2 1 # Levels: 1 2 3 So far so good. Now: contrasts(N)-contr.treatment(3, base=1, contrasts=FALSE) contrasts(N) # 1 2 # 1 1 0 # 2 0 1 # 3 0 0 whereas: contr.treatment(3, base=1, contrasts=FALSE) # 1 2 3 # 1 1 0 0 # 2 0 1 0 # 3 0 0 1 contr.treatment(3, base=1, contrasts=TRUE) # 2 3 # 1 0 0 # 2 1 0 # 3 0 1 I can follow the last two fine -- they are what is implied by the code for contr.treatment(). Likewise: contrasts(factor(Nlevs -c(1,2,3))) # 2 3 # 1 0 0 # 2 1 0 # 3 0 1 But why the different result when applied to N? With thanks, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 094 0861 Date: 20-May-08 Time: 01:12:30 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] recoding data with loops
Many, many thanks Erik! For anyone who is searching around looking for a way to recode in R, here's the full code Erik provided: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) ## my original list of variables mdf - data.frame(replicate(length(var_list), sample(7,100, replace = TRUE))) ## generate 100 records of random numbers sampled from 1:7 names(mdf) ## unnecessary, but helpful to see what R supplies as default names names(mdf) - var_list ## substitues my variable names mdf ## lovely! reverse_me_varnames - c(HEQUAL, HREVDIS1, HREVDIS2) ## these are the variables I want to reverse code reversed_varnames -paste(R, reverse_me_varnames, sep = ) ## this generates the names of the reversed variables by taking on an R mdf[reversed_varnames] - lapply(mdf[reverse_me_varnames], function(x) recode(x, recodes = 5:7=NA; 1=4; 2=3; 3=2; 4=1;, as.factor.result = FALSE)) ## this applies the recode function to all the variable I want to recode and stores them in the new R___ variables. mdf ## lovely! I really like that R doesn't even need to use loops to do this -- seems very efficient to me! On Mon, May 19, 2008 at 6:49 PM, Erik Iverson [EMAIL PROTECTED] wrote: Got it, I did not know of the 'recode' function in car. So you would like to recode those specific columns then? Once again, we can do it without a loop, this time with the help of a function called lapply, which applies a function to each item in a list in turn. Try: reverse_me_varnames - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_varnames -paste(R, reverse_me_varnames, sep = ) ## See ?paste mdf[reversed_varnames] - lapply(mdf[reverse_me_varnames], function(x) recode(x, recodes = 5:7=NA; 1=4; 2=3; 3=2; 4=1;, as.factor.result = FALSE)) Now what does this actually mean? To the left of '-' is simply the new columns of our data.frame. We want to then use lapply to do some function to a list of objects. The first argument to lapply is that list. In this case, it is simply the columns of the data.frame you want reversed. A data.frame is a list in R. See ?list and ?data.frame. Then, the next argument to lapply is a function that we want to perform on each element in our list. So, we create a function that accepts as input a variable I simply call 'x'. This 'x' is going to be an item from the list we passed lapply, which is one of the columns of mdf in 'reverse_me_varnames'. We then use the recode function in the car package to recode x, in a similar way to what you tried before. This function of x we define will get called three times in the above example, once for each of reverse_me_varnames. It will then assign those three new columns to the left-hand side of the - operator, which are three newly-named columns. To see why what you tried before did not work, with the for loop, try: mdf$HEQUAL contrasted with t1 - c(HEQUAL) mdf$t1 From the help for ?Extract, $ does not allow 'computed' indices. I hope this helps! Erik Donald Braman wrote: Erik, Your example was just what I needed to generate the data -- many, many thanks! The names() function was something I had not grasped fully. I now have this and it works very nicely: var_list - c(HEQUAL, EWEALTH, ERADEQ, HREVDIS1, EDISCRIM, HREVDIS2) mdf - data.frame(replicate(length(var_list), sample(7,100, replace = TRUE))) ## generate random data names(mdf) ## default names names(mdf) - var_list ## use our names mdf I'm still trying to figure out how to recode (using the car package) data into new variables using a similar loop. Basically, I'm not sure how to call the variable name and append it to the dataframe name in a loop. In Stata I'd do this using single quotes, but clearly that's not how R works. I tried several variations on this: reverse_me_varnames - c(HEQUAL, HREVDIS1, HREVDIS2) reversed_varnames - c(RHEQUAL, RHREVDIS1, RHREVDIS2) for(i in 1:length(reverse_me_varnames)) {mdf$reversed_varnames[i] - recode(mdf$reverse_me_varnames[i], '5:7=NA; 1=4; 2=3; 3=2; 4=1;', as.factor.result=FALSE) While I don't get an error message, the data don't change. Any advice on reverse coding non-continguous variables? On Mon, May 19, 2008 at 4:12 PM, Donald Braman [EMAIL PROTECTED]mailto: [EMAIL PROTECTED] wrote: Many thanks -- You are right; I had rnorm() and sample() mixed up in my code. I'll work on generating a normal ordinal sample next. Cheers, Don On Mon, May 19, 2008 at 4:07 PM, Erik Iverson [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Hello - Donald Braman wrote: # I'm new to R and am trying to get the hang of how it handles # dataframes loops. If anyone can help me with some simple tasks, # I'd be much obliged. # First, i'd like to generate some random data in a dataframe # to efficiently illustrate what I'm up to.
Re: [R] Need help in matrix multiplication error
Is this what you want: you need the 'drop=FALSE' to make sure it stays a matrix. data - read.table(textConnection( Statement T1001 T1002 T1003 T1004 T1005 T100 T1014 T1021 T1022 T1023 + 1 0 0 0 0 0 00 0 1 0 0 + 20 0 0 0 0 00 0 1 0 0 + 3 0 1 0 0 1 00 0 1 0 0 + 4 0 1 1 0 11 1 1 1 1 1), header=TRUE) data - as.matrix(data) str(data) int [1:4, 1:11] 0 0 0 0 0 0 1 1 0 0 ... - attr(*, dimnames)=List of 2 ..$ : chr [1:4] 1 2 3 4 ..$ : chr [1:11] Statement T1001 T1002 T1003 ... data[1:3,2:11]%*% sign(t(data[4,2:11, drop=FALSE])) 4 1 1 2 1 3 3 On Mon, May 19, 2008 at 7:43 PM, Jason Lee [EMAIL PROTECTED] wrote: Hi, I have a data file which is named test.txt as below. Prior to that, I have converted the last row from nominal to numeric using as.integer. Statement T1001 T1002 T1003 T1004 T1005 T100 T1014 T1021 T1022 T1023 1 0 0 0 0 0 00 0 1 0 0 20 0 0 0 0 00 0 1 0 0 3 0 1 0 0 1 00 0 1 0 0 4 406 pass pass fail pass pass pass pass pass pass pass After as.integer of pass, the below data is been transformed. Statement T1001 T1002 T1003 T1004 T1005 T100 T1014 T1021 T1022 T1023 1 0 0 0 0 0 00 0 1 0 0 20 0 0 0 0 00 0 1 0 0 3 0 1 0 0 1 00 0 1 0 0 4 0 1 1 0 11 1 1 1 1 1 The 1,2,3 and 4 on the first column is the automatic numbering seen on the terminal when i pasted here. And, i try to use matrix multiplication which is as.matrix(data[1:3,2:11])%*% sign(t(data[4,2:11])) Basically i wanted to count from column 2 onwards..which i want to ignore the Statement column data. Error in sign(t(data[4, 2:11])) : Non-numeric argument to mathematical function. I try take off the column constraint which is as.matrix(data[1:3,])%*% sign(t(data[4,])) but it still gives me Error in sign(t(data[4, ])) : Non-numeric argument to mathematical function I didnt understand how this error relate to my data above. Because my data is not a character at the first place and its a data.frame. Please help.Thanks.. Rgrds, Jason [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 2.7.0 graphics changes and png devices
The titles are in bold. Because the text is small, the weight is lower than in full-sized plots. The difference from 2.6.2 is that the text is correctly sized for the default 72dpi plots. Try something like png(width=7, height=7, units=in, res=96) for comparability with windows(). On Mon, 19 May 2008, Oliver Soong wrote: Hi, I have a question about the graphics changes in 2.7.0. The example is this bit of code: par(mfcol = c(2, 3)) for(i in 1:6) plot(1:10, 1:10, xlab = xlab, ylab = ylab, main = main) In 2.7.0, if I do this interactively (using windows()), I get bold titles. If I do this through a png device, I get regular weight titles. If I do this in 2.6.2, both situations give bold titles. I assume the 2.7.0 png device is off here, but I'm not sure how to fix this. Suggestions? Oliver __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.