[R] the function doesn´t work
hey, my function doesn´t work. can somebody help me? the graphic doesn´t work and also the function. thnx a lot. N=10 n=100 p_0=c(1/5,1-1/5) power = function(p,m) { set.seed(1000) H=matrix(0,nrow=N,ncol=1) for(i in 1:N) { x - matrix(rnorm(n, 0, 0.5), ncol = m) y - matrix(rnorm(n, 0, 0.8), ncol = m) l - diag(cor(x, y)) q_1 = qnorm(0.05, 0, 0.05) q_2 = qnorm(1 - 0.05, 0, 0.05) p - (l^2)/sum(l^2) H[i] - sum(p_0*log(p_0)) - sum(p * log(p)) } 1- mean(q_1 = H H = q_2) } m=seq(10,50,len=10) f=outer(p,m,Vectorize(power)) persp(p,m,power,theta=-50,phi=30,d=4,border=black) -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714105.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] the function doesn´t work
The message is clear. Just resove this problem before posting a terribly general and so not useful it does not work. Best mario f=outer(p,m,Vectorize(power)) Error in outer(p, m, Vectorize(power)) : object 'p' not found persp(p,m,power,theta=-50,phi=30,d=4,border=black) Error in persp(p, m, power, theta = -50, phi = 30, d = 4, border = black) : object 'p' not found On 26-Sep-10 08:39, jethi wrote: hey, my function doesn´t work. can somebody help me? the graphic doesn´t work and also the function. thnx a lot. N=10 n=100 p_0=c(1/5,1-1/5) power = function(p,m) { set.seed(1000) H=matrix(0,nrow=N,ncol=1) for(i in 1:N) { x- matrix(rnorm(n, 0, 0.5), ncol = m) y- matrix(rnorm(n, 0, 0.8), ncol = m) l- diag(cor(x, y)) q_1 = qnorm(0.05, 0, 0.05) q_2 = qnorm(1 - 0.05, 0, 0.05) p- (l^2)/sum(l^2) H[i]- sum(p_0*log(p_0)) - sum(p * log(p)) } 1- mean(q_1= H H= q_2) } m=seq(10,50,len=10) f=outer(p,m,Vectorize(power)) persp(p,m,power,theta=-50,phi=30,d=4,border=black) -- Ing. Mario Valle Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 __ 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] the function doesn´t work
hi, sorry but i can´t remove the problem.but i change the programm a little bit. i didn´t work with r programm before, so its really hard for me to find my problems. :) N=5 n=100 p_0=c(1/5,1-1/5) power = function(k1) { set.seed(1000) H=matrix(0,nrow=N,ncol=1) for(i in 1:N) { x - matrix(rnorm(n, 0, 0.5), ncol =m1) y - matrix(rnorm(n, 0, 0.8), ncol = m1) l - diag(cor(x, y)) q_1 = qnorm(0.05, 0, 0.05) q_2 = qnorm(1 - 0.05, 0, 0.05) p - (l^2)/sum(l^2) H[i] - sum(p_0*log(p_0)) - sum(p * log(p)) } 1- mean(q_1 = H H = q_2) } m1=seq(0,n/2,len=10) k1=1/m1 output - power(k1) f=outer(k1,Vectorize(power)) -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714123.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] acf function
Hi, Im new to R so this question is quite fundamental. Im trying to compare some autocorrelations generated by the acf function to some theoretical correlations. How can I have acces to just the autocorrelations, for computation? This is some of my code: acf.data-c(acf(x)) acf.data This is the R output: $acf , , 1 [,1] [1,] 1.0 [2,] 0.746183669 [3,] 0.551217818 [4,] 0.414995408 [5,] 0.313840795 [6,] 0.232915721 [7,] 0.173752145 [8,] 0.130249718 [9,] 0.089901832 [10,] 0.057342951 [11,] 0.030612095 [12,] 0.000951186 [13,] -0.021288467 [14,] -0.042727988 [15,] -0.055278855 [16,] -0.064782705 [17,] -0.067162534 $type [1] correlation $n.used [1] 50 $lag , , 1 [,1] [1,]0 [2,]1 [3,]2 [4,]3 [5,]4 [6,]5 [7,]6 [8,]7 [9,]8 [10,]9 [11,] 10 [12,] 11 [13,] 12 [14,] 13 [15,] 14 [16,] 15 [17,] 16 $series [1] x $snames NULL I need just the $acf values. How do I access them? I would really appreciate any advice. Thankyou. Regards, Andre [[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] Basis functions of cubic regression spline in mgcv
I have a question about the basis functions of cubic regression spline in mgcv. Are there some ways I can get the exact forms of the basis functions and the penalty matrix that are used in mgcv? Thanks in advance! Yan [[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] the function doesn´t work
This is worse than before and getting pretty silly. Now you are calling outer with a function that only takes one argument. R might be hard for you, but mind reading is even harder for most of us. To get help you need to explain clearly and sensibly what it is you want to do. Look at your code. You generate (the same) random numbers every time and do not use them. diag(cor(x,y)) is always a vector of ones. So p is the same at every stage of the loop as well. You put q_1 and q_2 inside the loop, but only use the outside. This is not R, this is just a failure to think clearly about what you are doing. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jethi Sent: Sunday, 26 September 2010 5:29 PM To: r-help@r-project.org Subject: Re: [R] the function doesn´t work hi, sorry but i can´t remove the problem.but i change the programm a little bit. i didn´t work with r programm before, so its really hard for me to find my problems. :) N=5 n=100 p_0=c(1/5,1-1/5) power = function(k1) { set.seed(1000) H=matrix(0,nrow=N,ncol=1) for(i in 1:N) { x - matrix(rnorm(n, 0, 0.5), ncol =m1) y - matrix(rnorm(n, 0, 0.8), ncol = m1) l - diag(cor(x, y)) q_1 = qnorm(0.05, 0, 0.05) q_2 = qnorm(1 - 0.05, 0, 0.05) p - (l^2)/sum(l^2) H[i] - sum(p_0*log(p_0)) - sum(p * log(p)) } 1- mean(q_1 = H H = q_2) } m1=seq(0,n/2,len=10) k1=1/m1 output - power(k1) f=outer(k1,Vectorize(power)) -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714123.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.
[R] Changing x-axis on boxplot
Dear List, I am creating a boxplot with two subsets, very similar to the example by Roger Bivand at ?boxplot (reproduced below). I am trying to change the labels on the x-axis to have one number to cover both subsets. I can do this in other plots by using axis=FALSE followed by a separate axis() command. I have also tried variations in the names= argument but can't get it to work. Ideally I would like tickmarks on either side of each factor with the number for the level centered between the two tick marks. Any suggestions? Thanks, Tim Example: boxplot(len ~ dose, data = ToothGrowth, boxwex = 0.25, at = 1:3 - 0.2, subset = supp == VC, col = yellow, main = Guinea Pigs' Tooth Growth, xlab = Vitamin C dose mg, ylab = tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i) boxplot(len ~ dose, data = ToothGrowth, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, subset = supp == OJ, col = orange) legend(2, 9, c(Ascorbic acid, Orange juice), fill = c(yellow, orange)) Tim Clark Marine Ecologist National Park of American Samoa __ 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] the function doesn´t work
It is not a problem of not knowing R. It is a problem of reasoning. if you use m1 and not assign to it a value beforehand it is difficult your function works. And this will happen in any language, not only R. Maybe explaining what you are trying to do helps. To do this try to add comments (starting with #) to your code. Reading error messages is always useful too. Best mario On 26-Sep-10 09:28, jethi wrote: hi, sorry but i can´t remove the problem.but i change the programm a little bit. i didn´t work with r programm before, so its really hard for me to find my problems. :) N=5 n=100 p_0=c(1/5,1-1/5) power = function(k1) { set.seed(1000) H=matrix(0,nrow=N,ncol=1) for(i in 1:N) { x- matrix(rnorm(n, 0, 0.5), ncol =m1) y- matrix(rnorm(n, 0, 0.8), ncol = m1) l- diag(cor(x, y)) q_1 = qnorm(0.05, 0, 0.05) q_2 = qnorm(1 - 0.05, 0, 0.05) p- (l^2)/sum(l^2) H[i]- sum(p_0*log(p_0)) - sum(p * log(p)) } 1- mean(q_1= H H= q_2) } m1=seq(0,n/2,len=10) k1=1/m1 output- power(k1) f=outer(k1,Vectorize(power)) -- Ing. Mario Valle Data Analysis and Visualization Group| http://www.cscs.ch/~mvalle Swiss National Supercomputing Centre (CSCS) | Tel: +41 (91) 610.82.60 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax: +41 (91) 610.82.82 __ 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] the function doesn´t work
i´m really sorry, once again. ok i will try to explain what i have to programm. i want to programm a powerfunction. i have to research if the correlations in a bivariate random sample are homogeneous. for that i saperate the random sample in m blocks and calculate the correlation of each block(partial sample). than i look at the random variable p=cor(x1,y1)^2/sum(cor(x,y)^2) which is a probability. my null hypothesis is that all correlations are homogeneous. if we have this situation the entropy take the value log(m). my test based on the entropy. so my teststatic is H=log(m)-sum(p*log(p)). the following programm was actually, which i have worked the most of the time. i hope that i don´t confuse u too much. i of course i hope u understand my problem and my theme. n=1000 m=2 k=n/m N=100 myfun - function(n, m, alpha = .05, seeder = 1000) { l=matrix(0,nrow=m,ncol=N) for(i in 1:N){ set.seed(i) for(j in 1:m){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } gute - function(x,m) { q_1 - qnorm(alpha, 0, 0.05) q_2 - qnorm(1 - alpha, 0, 0.05) p=matrix(0,nrow=m,ncol=N) H=matrix(0,nrow=N,ncol=1) for(i in 1:N){ for (j in 1:m){ p[j,i]=x[j]^2/sum(x[,i]^2) } H[i]=log(m)-sum(p[,i]*log(p[,i])) } 1 - mean(q_1 = H H = q_2) } output - gute(x = l,m=m) return(output) } -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714137.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] why I could not reproduce the Mandelbrot plot demonstrated on R wiki
On 09/26/2010 04:50 AM, xin wei wrote: hi, peter: thank you for your attention. adding the line you suggested did display the static Mandelbrot plot with good resolution on R graphics device. However, the resulting gif file still come out ugly. the R wiki page I was referring to is the following: http://en.wikipedia.org/wiki/R_(programming_language) where the nice Mandelbrot plot and sample codes are provided. i would appreciate your help if you can provide further hint. The caTools package might have changed since the Wikipedia graphic was created, so perhaps you should ask its maintainer. I see an autoscale feature that you might want to turn off. (Sorry that I can't be more specific, but it would be overkill for me to install caTools and start experimenting with it. After all, it is your problem, not mine.) -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.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] get absolute file path
Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName - ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian __ 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] acf function
Hi Andre, try acf.data$acf regards, Theresa andre bedon wrote: Hi, Im new to R so this question is quite fundamental. Im trying to compare some autocorrelations generated by the acf function to some theoretical correlations. How can I have acces to just the autocorrelations, for computation? This is some of my code: acf.data-c(acf(x)) acf.data This is the R output: $acf , , 1 [,1] [1,] 1.0 [2,] 0.746183669 [3,] 0.551217818 [4,] 0.414995408 [5,] 0.313840795 [6,] 0.232915721 [7,] 0.173752145 [8,] 0.130249718 [9,] 0.089901832 [10,] 0.057342951 [11,] 0.030612095 [12,] 0.000951186 [13,] -0.021288467 [14,] -0.042727988 [15,] -0.055278855 [16,] -0.064782705 [17,] -0.067162534 $type [1] correlation $n.used [1] 50 $lag , , 1 [,1] [1,]0 [2,]1 [3,]2 [4,]3 [5,]4 [6,]5 [7,]6 [8,]7 [9,]8 [10,]9 [11,] 10 [12,] 11 [13,] 12 [14,] 13 [15,] 14 [16,] 15 [17,] 16 $series [1] x $snames NULL I need just the $acf values. How do I access them? I would really appreciate any advice. Thankyou. Regards, Andre [[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] get absolute file path
Le 26/09/10 10:00, Sebastian Gibb a écrit : Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName- ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian Hi, I often use tools:::file_path_as_absolute which is not exported from the tools namespace, but does the job. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cCmbgg : Rcpp 0.8.6 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 `- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th __ 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] get absolute file path
The package R.utils has a function to get absolutepath On Sun, Sep 26, 2010 at 1:00 AM, Sebastian Gibb li...@sebastiangibb.dewrote: Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName - ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian __ 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] get absolute file path
Am Sonntag, 26. September 2010, 10:08:39 schrieb Romain Francois: Le 26/09/10 10:00, Sebastian Gibb a écrit : Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName- ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian Hi, I often use tools:::file_path_as_absolute which is not exported from the tools namespace, but does the job. Romain Hello Romain, thank you, this function works like expected. Why is it hidden? Kind regards, Sebastian __ 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] get absolute file path
On 26/09/2010 4:08 AM, Romain Francois wrote: Le 26/09/10 10:00, Sebastian Gibb a écrit : Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName- ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian Hi, I often use tools:::file_path_as_absolute which is not exported from the tools namespace, but does the job. Or use normalizePath, exported from utils. 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] Changing x-axis on boxplot
Hi, to hide the axis generated by bxp you have to set axes=FALSE and frame.plot=FALSE and then you can plot the x-axis by using the axis() function example: boxplot(len ~ dose, data = ToothGrowth, frame.plot=FALSE,axes=FALSE, boxwex = 0.25, at = 1:3 - 0.2, subset = supp == VC, col = yellow, main = Guinea Pigs' Tooth Growth, xlab = Vitamin C dose mg, ylab = tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35)) boxplot(len ~ dose, data = ToothGrowth, add = TRUE, frame.plot=FALSE,axes=FALSE, boxwex = 0.25, at = 1:3 + 0.2, subset = supp == OJ, col = orange) axis(1,at=0:4) axis(2,at=(0:17)*2) legend(2, 9, c(Ascorbic acid, Orange juice), fill = c(yellow, orange)) Theresa Tim Clark wrote: Dear List, I am creating a boxplot with two subsets, very similar to the example by Roger Bivand at ?boxplot (reproduced below). I am trying to change the labels on the x-axis to have one number to cover both subsets. I can do this in other plots by using axis=FALSE followed by a separate axis() command. I have also tried variations in the names= argument but can't get it to work. Ideally I would like tickmarks on either side of each factor with the number for the level centered between the two tick marks. Any suggestions? Thanks, Tim Example: boxplot(len ~ dose, data = ToothGrowth, boxwex = 0.25, at = 1:3 - 0.2, subset = supp == VC, col = yellow, main = Guinea Pigs' Tooth Growth, xlab = Vitamin C dose mg, ylab = tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i) boxplot(len ~ dose, data = ToothGrowth, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, subset = supp == OJ, col = orange) legend(2, 9, c(Ascorbic acid, Orange juice), fill = c(yellow, orange)) Tim Clark Marine Ecologist National Park of American Samoa __ 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 required
In a context of spatial analysis, see also readGDAL in package rgdal: library(rgdal) logo - system.file(pictures/logo.jpg, package=rgdal)[1] x - readGDAL(logo) image(x) Renaud 2010/9/25 Prof Brian Ripley rip...@stats.ox.ac.uk: On Sat, 25 Sep 2010, Malik Shahzad wrote: Is it possible to read jpeg files into R? If yes please guide, Thanks.. I tried to search many time but failed to do. On my system ??jpeg gave ReadImages::read.jpeg Read JPEG file biOps::readJpeg Read jpeg file rimage::read.jpeg Read JPEG file There are a number of other possibilities, including EBImage::readImage from Bioconductor which uses ImageMagick to convert the file format (and that or many other image convertors could be used in a simple R wrapper). Thankis in advance.. with Best Regards, Malik Shahzad Visiting Researcher National Institute of Informatics (NII) Tokyo, Japan Doctoral Student Asian Institute of Technology (AIT) Bangkok, Thailand +66-8-7676-5616 [[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, rip...@stats.ox.ac.uk 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, UK Fax: +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. -- Renaud Lancelot EDEN Project, coordinator http://www.eden-fp6project.net/ UMR CIRAD-INRA Contrôle des maladies animales exotiques et émergentes Joint research unit Control of emerging and exotic animal diseases CIRAD, Campus International de Baillarguet TA A-DIR / B F34398 Montpellier http://umr-cmaee.cirad.fr/ Tel. +33 4 67 59 37 17 - Fax +33 4 67 59 37 95 Secr. +33 4 67 59 37 37 - Cell. +33 6 77 52 08 69 __ 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] OT: What distribution is this?
On 09/26/2010 10:29 AM, Rainer M Krug wrote: Hi Peter, H Berwin, thanks a lot for your clarifications, it makes more sense now. But having our input and thinking a little bit more about the problem, I realized that I am simply interested in the pdf p(y) that y *number* of entities (which ones is irrelevant) in N are are *not* drawn after the sampling process has been completed. Even simpler (I guess), in a first step, I would only need the mean number of expected non-drawn entities in N (pMean). The range of my values: N is in the range of 1 --- 100 000 x is in the range of 10 --- 40 000 000 n is in the range of 20 I guess in cases where n*x is substantially smaller then N, I could simply use a binominal distribution for n*x samples to approximate it -- right? For cases where n*x is substantially bigger then N, I can safely (especially in the context of my simulation) assume that all entities in N are drawn at least once. But what about the range in between? As long as you are only looking for the mean, I think it is easy: The probability that a particular entity is not sampled in x trials is ((N-n)/N)^x and the mean number of such entities is just N times as much. The variance is slightly harder, but not excessively so (read: I know that you start by working out the probabilities in the 2x2 tables of the joint distribution of two indicators for an entity never being sampled, use this to get the covariance, etc., I just haven't actually done it.) -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.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] get absolute file path
Sebastian Gibb writes: Am Sonntag, 26. September 2010, 10:08:39 schrieb Romain Francois: Le 26/09/10 10:00, Sebastian Gibb a écrit : Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName- ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian Hi, I often use tools:::file_path_as_absolute which is not exported from the tools namespace, but does the job. Romain Hello Romain, thank you, this function works like expected. Why is it hidden? Afaics it is exported and documented. -k Kind regards, Sebastian __ 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] get absolute file path
Le 26/09/10 12:18, Kurt Hornik a écrit : Sebastian Gibb writes: Am Sonntag, 26. September 2010, 10:08:39 schrieb Romain Francois: Le 26/09/10 10:00, Sebastian Gibb a écrit : Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName- ../data/2010-08.csv; Is it possible to get the absolute file path out of this value? (e.g. /home/sebastian/documents/data/2010-08.csv) Kind regards, Sebastian Hi, I often use tools:::file_path_as_absolute which is not exported from the tools namespace, but does the job. Romain Hello Romain, thank you, this function works like expected. Why is it hidden? Afaics it is exported and documented. oops. -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cCmbgg : Rcpp 0.8.6 |- http://bit.ly/bzoWrs : Rcpp svn revision 2000 `- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th __ 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] Changing x-axis on boxplot
Hi: Here are a couple of ways: (1) Base graphics: add argument axes = FALSE to both plots, then add axes boxplot(len ~ dose, data = subset(ToothGrowth, supp == 'VC'), boxwex = 0.25, at = 1:3 - 0.2, col = yellow, main = Guinea Pigs' Tooth Growth, axes = FALSE, xlab = Vitamin C dose mg, ylab = Tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i) boxplot(len ~ dose, data = subset(ToothGrowth, supp == 'OJ'), add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, axes = FALSE, col = orange) axis(1, at = 1:3, labels = c(0.5, 1, 2)) axis(2) legend(2, 9, c(Ascorbic acid, Orange juice), fill = c(yellow, orange)) box() (2) ggplot2 (just for fun :) library(ggplot2) g - ggplot(ToothGrowth, aes(x = factor(dose), y = len)) g + geom_boxplot(aes(fill = supp), position = position_dodge(width = 0.9)) + scale_fill_manual('', breaks = c('OJ', 'VC'), values = c('orange', 'yellow'), labels = c('Orange juice', 'Ascorbic acid')) + theme_bw() + opts(legend.position = c(0.8, 0.2), legend.text = theme_text(size = 12)) + opts(panel.grid.major = theme_blank()) + xlab('Vitamin C dose (mg)') + ylab('Tooth length') + opts(title = Guinea pigs' tooth growth) + opts(plot.title = theme_text(size = 16)) HTH, Dennis On Sat, Sep 25, 2010 at 11:13 PM, Tim Clark mudiver1...@yahoo.com wrote: Dear List, I am creating a boxplot with two subsets, very similar to the example by Roger Bivand at ?boxplot (reproduced below). I am trying to change the labels on the x-axis to have one number to cover both subsets. I can do this in other plots by using axis=FALSE followed by a separate axis() command. I have also tried variations in the names= argument but can't get it to work. Ideally I would like tickmarks on either side of each factor with the number for the level centered between the two tick marks. Any suggestions? Thanks, Tim Example: boxplot(len ~ dose, data = ToothGrowth, boxwex = 0.25, at = 1:3 - 0.2, subset = supp == VC, col = yellow, main = Guinea Pigs' Tooth Growth, xlab = Vitamin C dose mg, ylab = tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i) boxplot(len ~ dose, data = ToothGrowth, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, subset = supp == OJ, col = orange) legend(2, 9, c(Ascorbic acid, Orange juice), fill = c(yellow, orange)) Tim Clark Marine Ecologist National Park of American Samoa __ 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] OT: What distribution is this?
G'day Rainer, On Sun, 26 Sep 2010 10:29:08 +0200 Rainer M Krug r.m.k...@gmail.com wrote: I realized that I am simply interested in the pdf p(y) that y *number* of entities (which ones is irrelevant) in N are are *not* drawn after the sampling process has been completed. Even simpler (I guess), in a first step, I would only need the mean number of expected non-drawn entities in N (pMean). But what about the range in between? You can calculate those probilities. Your problem was sounding vaguely familiar to me yesterday but I could not put my finger onto its abstract counterpart. Now with this clarification I can. :) Your set up is exactly the one of lottery draws. In each draw n of N numbers are drawn without replacement. So your question is what is the probability that I have not seen k of the N numbers after x draws?. This question can easily be answered by using some Markov Chain theory. Let Y_l be the number of entities that you have not seen after the l-th draw, taking possible values 0, 1, , N. Obviously, Y_0=N with probability 1, and Y_1=N-n with probability 1. Now, the probability that Y_l, l=1, is equal to k is given by; 0 if k=N-n+1, N-n+2,..., N and sum_{i=0,...,n} P[Y_l=k | Y_{l-1} = k+i] P[Y_{l-1} = k+i] o/w. P[Y_l=k | Y_{l-1} = k+i] is the probability that the n entities sampled in the l-th draw consists of i entities of the k+i entities that were not seen by draw l-1 and n-i entities of the N-k-i entities that were already seen by draw l-1. This probability is choose(k+i, i)*choose(N-k-i, n-i) / choose(N, n) Note that this probability is independent of l, i.e., Y_0, Y_1, Y_2,... form a stationary Markov Chain. Thus, to answer your question, the strategy would be to calculate the transition matrix once and then start with either the state vector of Y_0 or of Y_1 (both of which are rather trivial as mentioned above) and calculate the state vector of Y_x by repeatedly multiplying the chosen initial state vector with the transition matrix for the appropriate number of times. The transition matrix is (N+1)x(N+1), so it can be rather large, but the number of non-zero entries in the transition matrix is at most (N+1)*(n+1), so depending on the relative magnitude of n and N, sparse matrix techniques might be helpful (or using a language such as C, FOTRAN, ... for the calculations). HTH. Cheers, Berwin __ 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] matrix help
Anyone know how write a function that solves: (1 + c)x1 +x2 +x3 = 5 x1+(1 + c)x2+x3 = 5 + 2c x1+x2 +(1 + c)x3= 5 + 3c, where c is a small constant, for 1000 equidistant values c = (10^-14, 2*10^-14, ..., 10^-11) by using cholesky decomposition? /P -- View this message in context: http://r.789695.n4.nabble.com/matrix-help-tp2714378p2714378.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] formatting data for predict()
Hi Andrew, My inclination would be to put all the variables in a data.frame instead of putting the predictors in a matrix. But if you want to continue down this road, you need to have a column named dat in a the data.frame that contains a matrix. I couldn't figure out how to do such a thing in a single call, so I had to create it in a separate step: newdat - data.frame(y=rep(NA, length(unique(x1 newdat$dat - cbind(unique(x1), x2=0) p2a=predict(mod2, type=response, newdata=newdat) p2a Hope it helps, Ista On Sun, Sep 26, 2010 at 4:38 AM, Andrew Miles rstuff.mi...@gmail.com wrote: I'm trying to get predicted probabilities out of a regression model, but am having trouble with the newdata option in the predict() function. Suppose I have a model with two independent variables, like this: y=rbinom(100, 1, .3) x1=rbinom(100, 1, .5) x2=rnorm(100, 3, 2) mod=glm(y ~ x1 + x2, family=binomial) I can then get the predicted probabilities for the two values of x1, holding x2 constant at 0 like this: p2=predict(mod, type=response, newdata=as.data.frame(cbind(x1, x2=0))) unique(p2) However, I am running regressions as part of a function I wrote, which feeds in the independent variables to the regression in matrix form, like this: dat=cbind(x1, x2) mod2=glm(y ~ dat, family=binomial) The results are the same as in mod. Yet I cannot figure out how to input information into the newdata option of predict() in order to generate the same predicted probabilities as above. The same code as above does not work: p2a=predict(mod2, type=response, newdata=as.data.frame(cbind(x1, x2=0))) unique(p2a) Nor does creating a data frame that has the names datx1 and datx2, which is how the variables appear if you run a summary() on mod2. Looking at the model matrix of mod2 shows that the fitted model only shows two variables, the dependent variable y and one independent variable called dat. It is as if my two variables x1 and x2 have become two levels in a factor variable called dat. names(mod2$model) My question is this: if I have a fitted model like mod2, how do I use the newdata option in the predict function so that I can get the predicted values I am after? I.E. how do I recreate a data frame with one variable called dat that contains two levels which represent my (modified) variables x1 and x2? Thanks in advance! Andrew Miles Department of Sociology Duke University __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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] compare a vector and a row of a matrix
From: xxgr...@hotmail.com To: r-help-boun...@r-project.org Subject: compare a vector and a row of a matrix Date: Sun, 26 Sep 2010 23:23:52 +0800 Hi Everyone: I am trying to compare a vector and rows of a matrix for example xn - c(1,2,4,4,5,5,5,6) yn - c(1,2,5,7,1,2,3,1) mtrx - cbind(xn, yn) when I tried, say, c (1,4), the result was TRUE, TRUE. I think the reason is that 1 is compared to xn and 4 is compared to yn seperately. Could anyone tell me how I can get a single result of the comparson between a vector and a row of the matrix? for example£¬ c(1,1) is one row of the matrix but c(1,4) is not. I tried to write a loop but it seems long for this simple problem Thank you very much!!! [[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] 3D plot
jethi kartija at hotmail.com writes: hey, is there anybody who can help me? its very urgent because i have to send my bachelor thesis on monday. pls help me I'm really sorry that you're stuck, but ... waiting until a few days before an important assignment is due and then depending on the generosity of unpaid volunteers is a dangerous procedure ... I tried to run your code but got an error (object 'p' not found); it's very hard to understand what the code is doing, there are lots of things that look funny/wrong ... in particular, you should look at the gute() function and think about what it's doing. Be aware that functions in R do not work like 'macros', that is, information about variables that are defined or modified within functions does not propagate outside the functions. If you post a function that actually works, you are more likely to get help drawing the graph. If your results are in the form of a matrix, persp() is probably the easiest way to draw the surface. wireframe (in the lattice package) is an alternative. __ 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] OT: What distribution is this?
Hi Peter, H Berwin, thanks a lot for your clarifications, it makes more sense now. But having our input and thinking a little bit more about the problem, I realized that I am simply interested in the pdf p(y) that y *number* of entities (which ones is irrelevant) in N are are *not* drawn after the sampling process has been completed. Even simpler (I guess), in a first step, I would only need the mean number of expected non-drawn entities in N (pMean). The range of my values: N is in the range of 1 --- 100 000 x is in the range of 10 --- 40 000 000 n is in the range of 20 I guess in cases where n*x is substantially smaller then N, I could simply use a binominal distribution for n*x samples to approximate it -- right? For cases where n*x is substantially bigger then N, I can safely (especially in the context of my simulation) assume that all entities in N are drawn at least once. But what about the range in between? Thanks again, Cheers, Rainer On Sat, Sep 25, 2010 at 5:19 PM, Peter Dalgaard pda...@gmail.com wrote: On 09/25/2010 04:24 PM, Rainer M Krug wrote: Hi This is OT, but I need it for my simulation in R. I have a special case for sampling with replacement: instead of sampling once and replacing it immediately, I sample n times, and then replace all n items. So: N entities x samples with replacement each sample consists of n sub-samples WITHOUT replacement, which are all replaced before the next sample is drawn My question is: which distribution can I use to describe how often each entity of the N has been sampled? Thanks for your help, Rainer How did you know I was in the middle of preparing lectures on the variance of the hypergeometric distribution and such? ;-) If you look at a single item, the answer is of course that you have a binomial with size=x and prob=n/N. The problem is that these binomials are correlated between items. If you can make do with a 2nd order approximation, then the covariances between the indicators for two items being selected is easily found from the symmetry and the fact that if you sum all N indicators you get the constant n. I.e. the variance is p(1-p) and the covariance is -p(1-p)/(N-1). For sums over repeated samples, just multiply everything by the number x of samples. If you intend to just count the frequency of a particular feature in each of your n-samples, i.e., you have x replications of a hypergeometric experiment, then you can do somewhat better by computing the explicit convolution of x hypergeometrics (convolve(x, rev(y), type=o) and Reduce() are your friends). I'm not sure this is actually worth the trouble, but it should be doable for decent-sized N and x. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com -- NEW GERMAN FAX NUMBER!!! Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Cell: +27 - (0)83 9479 042 Fax:+27 - (0)86 516 2782 Fax:+49 - (0)321 2125 2244 email: rai...@krugs.de Skype: RMkrug Google: r.m.k...@gmail.com [[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] Splitting a data frame into several completely separate data frames
Hello again, How do I split a data frame into smaller, completely separate data frames (rather than separate data frames comprising a single list)? Consider the following data, and my coding attempt: x - read.table(textConnection(id type number indv.1 bagel 6 indv.2 bagel 1 indv.3 donuts 10 indv.4 donuts 9), header = TRUE) closeAllConnections() x.split - split(x, x$type) This is where I'm stuck. Now I have one list comprised of different data frames, but what I want is separate data frames. Ideally, I'd like to design a loop to give sequentially-numbered names to the separate data frames I create. This is because my real data will have many more than two groups (i.e., many more types of things than just bagels versus donuts) and the number of groups will vary when I apply the same code to different data sets. Many thanks in advance for your replies! --- Josh Banta, Ph.D Center for Genomics and Systems Biology New York University 100 Washington Square East New York, NY 10003 Tel: (212) 998-8465 http://plantevolutionaryecology.org [[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] Good documentation about Sweave
Hello, I am looking for a good and detailed documentation about Sweave... but can't find anything more that 15 pages asking Google... Any hint on that point ? Cheers Colin -- View this message in context: http://r.789695.n4.nabble.com/Good-documentation-about-Sweave-tp2714326p2714326.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] efficient equivalent to read.csv / write.csv
Hello everyone, I currently run R code that have to read 100 or more large csv files (= 100 Mo), and usually write csv too. My collegues and I like R very much but are a little bit ashtonished by how slow those functions are. We have looked on every argument of those functions and if specifying some parameters help a bit, this is still too slow. I am sure a lot of people have the same problem so I thought one of you would know a trick or a package that would help speeding this up a lot. (we work on LINUX Red Hat R 2.10.0 but I guess this is of no use for this pb) Thanks for reading this. Have a nice week end -- View this message in context: http://r.789695.n4.nabble.com/efficient-equivalent-to-read-csv-write-csv-tp2714325p2714325.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] compare a vector and a row of a matrix
Hi, You can use all.equal, like this: all.equal(c(1,1), mtrx[1,], check.attributes=FALSE) If you want to check each row of the matrix (I wasn't clear if you wanted this) you can do something like check.equal - function(x, y) { isTRUE(all.equal(y, x, check.attributes=FALSE)) } apply(mtrx, 1, check.equal, y=c(1,1)) HTH, Ista On Sun, Sep 26, 2010 at 3:25 PM, xinxin xx xxgr...@hotmail.com wrote: From: xxgr...@hotmail.com To: r-help-boun...@r-project.org Subject: compare a vector and a row of a matrix Date: Sun, 26 Sep 2010 23:23:52 +0800 Hi Everyone: I am trying to compare a vector and rows of a matrix for example xn - c(1,2,4,4,5,5,5,6) yn - c(1,2,5,7,1,2,3,1) mtrx - cbind(xn, yn) when I tried, say, c (1,4), the result was TRUE, TRUE. I think the reason is that 1 is compared to xn and 4 is compared to yn seperately. Could anyone tell me how I can get a single result of the comparson between a vector and a row of the matrix? for example, c(1,1) is one row of the matrix but c(1,4) is not. I tried to write a loop but it seems long for this simple problem Thank you very much!!! [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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] efficient equivalent to read.csv / write.csv
On Sun, Sep 26, 2010 at 8:38 AM, statquant2 statqu...@gmail.com wrote: Hello everyone, I currently run R code that have to read 100 or more large csv files (= 100 Mo), and usually write csv too. My collegues and I like R very much but are a little bit ashtonished by how slow those functions are. We have looked on every argument of those functions and if specifying some parameters help a bit, this is still too slow. I am sure a lot of people have the same problem so I thought one of you would know a trick or a package that would help speeding this up a lot. (we work on LINUX Red Hat R 2.10.0 but I guess this is of no use for this pb) Thanks for reading this. Have a nice week end You could try read.csv.sql in the sqldf package: http://code.google.com/p/sqldf/#Example_13._read.csv.sql_and_read.csv2.sql See ?read.csv.sql in sqldf. It uses RSQLite and SQLite to read the file into an sqlite database (which it sets up for you) completely bypassing R and from there grabs it into R removing the database it created at the end. There are also CSVREAD and CSVWRITE sql functions in the H2 database which is also supported by sqldf although I have never checked their speed: http://code.google.com/p/sqldf/#10.__What_are_some_of_the_differences_between_using_SQLite_and_H -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] Good documentation about Sweave
SWeave is a very nice and simple to use tool, hence 15 pages sound very appropriate to get started. Uwe Ligges On 26.09.2010 14:41, statquant2 wrote: Hello, I am looking for a good and detailed documentation about Sweave... but can't find anything more that 15 pages asking Google... Any hint on that point ? Cheers Colin __ 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] efficient equivalent to read.csv / write.csv
On 26.09.2010 14:38, statquant2 wrote: Hello everyone, I currently run R code that have to read 100 or more large csv files (= 100 Mo), and usually write csv too. My collegues and I like R very much but are a little bit ashtonished by how slow those functions are. We have looked on every argument of those functions and if specifying some parameters help a bit, this is still too slow. I am sure a lot of people have the same problem so I thought one of you would know a trick or a package that would help speeding this up a lot. (we work on LINUX Red Hat R 2.10.0 but I guess this is of no use for this pb) Thanks for reading this. Have a nice week end Most of us read the csv file and write an Rdata file at once (see ?save). Then we can read in the data much quicker after they have been imported once with read.csv and friends. Uwe Ligges __ 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] Splitting a data frame into several completely separate data frames
On 26.09.2010 14:52, Josh B wrote: Hello again, How do I split a data frame into smaller, completely separate data frames (rather than separate data frames comprising a single list)? Consider the following data, and my coding attempt: x- read.table(textConnection(id type number indv.1 bagel 6 indv.2 bagel 1 indv.3 donuts 10 indv.4 donuts 9), header = TRUE) closeAllConnections() x.split- split(x, x$type) Although I doubt it is more convenient to have so many data.frames around (rather than having them nicely grouped in a list), you can simply do that in a loop: for(i in names(x.split)) assign(paste(nameOfDataFrame, i, sep=_), temp[[i]]) Uwe Ligges This is where I'm stuck. Now I have one list comprised of different data frames, but what I want is separate data frames. Ideally, I'd like to design a loop to give sequentially-numbered names to the separate data frames I create. This is because my real data will have many more than two groups (i.e., many more types of things than just bagels versus donuts) and the number of groups will vary when I apply the same code to different data sets. Many thanks in advance for your replies! --- Josh Banta, Ph.D Center for Genomics and Systems Biology New York University 100 Washington Square East New York, NY 10003 Tel: (212) 998-8465 http://plantevolutionaryecology.org [[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] Newbie Correspondence Analysis Question
I'm experienced in statistics, but I am a first-time R user. I would like to use R for correspondence analysis. I have installed R (Mac OSX). I have used the package installer to install the CA package. I have run the following line with no errors to read in the data for a table: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) The R online help appears to suggest that the following line should come next: corresp(NonLuxury) However, I get the error message: Error: could not find function corresp The CA manual appears to suggest that the following line should come next: ca(NonLuxury) Again, I get the error message: Error: could not find function ca What am I missing? Thanks very much in advance to all for any info. -Vik __ 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] Splitting a data frame into several completely separate data frames
On Sun, Sep 26, 2010 at 8:52 AM, Josh B josh...@yahoo.com wrote: Hello again, How do I split a data frame into smaller, completely separate data frames (rather than separate data frames comprising a single list)? Consider the following data, and my coding attempt: x - read.table(textConnection(id type number indv.1 bagel 6 indv.2 bagel 1 indv.3 donuts 10 indv.4 donuts 9), header = TRUE) closeAllConnections() x.split - split(x, x$type) This is where I'm stuck. Now I have one list comprised of different data frames, but what I want is separate data frames. Ideally, I'd like to design a loop to give sequentially-numbered names to the separate data frames I create. This is because my real data will have many more than two groups (i.e., many more types of things than just bagels versus donuts) and the number of groups will vary when I apply the same code to different data sets. Its normally better to keep them in a list but if you must: attach(x.split) bagel id type number 1 indv.1 bagel 6 2 indv.2 bagel 1 Note that the attach puts the individual data frames in position 2 of your search list and not in your workspace so its mainly useful if you don't need to modify them. e.g. try this to see your search list: search() and this to list them: ls(2) [1] bagel donuts ls(as.environment(x.split)) [1] bagel donuts If you want to be able to modify them or to have them directly in your global workspace then use Uwe's answer. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] Saving iterative components
On 24.09.2010 17:51, Annalaura wrote: Hi, I need help! I am trying to iterate an iterative process to do cross vadation and store the results each time. I have a Spatial data.frame, called Tmese str(Tmese) Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots ..@ data :'data.frame': 14 obs. of 17 variables: .. ..$ ID : int [1:14] 73 68 49 62 51 79 69 77 57 53 ... .. ..$ Stazione: Factor w/ 29 levels ALIANO,BONIFATI,..: 2 3 4 5 10 11 12 16 17 19 ... .. ..$ X01_1994: num [1:14] 9.34 10.67 5.29 11.86 9.15 ... .. ..$ X01_1995: num [1:14] 7.07 9.22 2.32 9.3 6.66 ... .. ..$ X01_1996: num [1:14] 9.41 10.4 5.99 12.3 9.93 ... .. ..$ X01_1997: num [1:14] 10.67 10.65 5.76 12.82 10.1 ... .. ..$ X01_1998: num [1:14] 9.57 10.12 4.44 10.34 8.97 ... .. ..$ X01_1999: num [1:14] 8.96 10.21 3.23 10.83 7.74 ... .. ..$ X01_2000: num [1:14] 6.58 8.46 2.8 8.37 6.55 ... Now I want to do 14 cross validation and I wrote a function idw.cv- function(x){ tmp- krige.cv(x~1, Tmese, model=NULL) return(tmp) } But when I run it, it doesn't work, it says: cv_1994- idw.cv(X01_1994) Actually this means that you want to pass an object called X01_1994 to the function rather than a symbol for the formula. What you could do in order to stay with the formula notation is to write your own generic / methods that handles different kinds of input including formulae and handle them. Otherwise a quick and dirty approach (with some shortcomings) for example is: idw.cv- function(x){ form - as.formula(paste(x, ~1)) tmp- krige.cv(form, Tmese, model=NULL) return(tmp) } cv_1994- idw.cv(X01_1994) Uwe Ligges Error in eval(expr, envir, enclos) : object 'X01_1994' not found WhyPlease Help me! __ 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] Newbie Correspondence Analysis Question
Hi Vik, You need to load the CA package first: library(CA) -Ista On Sun, Sep 26, 2010 at 4:41 PM, Vik Rubenfeld v...@mindspring.com wrote: I'm experienced in statistics, but I am a first-time R user. I would like to use R for correspondence analysis. I have installed R (Mac OSX). I have used the package installer to install the CA package. I have run the following line with no errors to read in the data for a table: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) The R online help appears to suggest that the following line should come next: corresp(NonLuxury) However, I get the error message: Error: could not find function corresp The CA manual appears to suggest that the following line should come next: ca(NonLuxury) Again, I get the error message: Error: could not find function ca What am I missing? Thanks very much in advance to all for any info. -Vik __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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 update an old unsupported package
Hi all, I have a package that is specific to a task I was repetitively using a few years ago. I now needed to run it again with new data. However I am told it was built with an older version or R and will not work. How can I tweak the package so it will run on 11.1? It was a one-off product and has not been maintained. Is there a way to unpackage it and repackage it to work? I tried just changing the date and R version in the DESCRIPTION file but that did not help. Tnx Bruce __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to update an old unsupported package
On 26.09.2010 19:19, Neotropical bat risk assessments wrote: Hi all, I have a package that is specific to a task I was repetitively using a few years ago. I now needed to run it again with new data. However I am told it was built with an older version or R and will not work. How can I tweak the package so it will run on 11.1? You probably mean R-2.11.1? It was a one-off product and has not been maintained. Is there a way to unpackage it and repackage it to work? Well, take the source package, run tar xfz packagename_version.tar.gz and you have the sources that you can modify and repackage and reinstall afterwards. See the manual Writing R Extensions fir detaiks. Best, Uwe Ligges I tried just changing the date and R version in the DESCRIPTION file but that did not help. Tnx Bruce __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to update an old unsupported package
On Sun, Sep 26, 2010 at 1:19 PM, Neotropical bat risk assessments neotropical.b...@gmail.com wrote: Hi all, I have a package that is specific to a task I was repetitively using a few years ago. I now needed to run it again with new data. However I am told it was built with an older version or R and will not work. How can I tweak the package so it will run on 11.1? It was a one-off product and has not been maintained. Is there a way to unpackage it and repackage it to work? I tried just changing the date and R version in the DESCRIPTION file but that did not help. Tnx Bruce You can: (1) use the old version of R that you previously used and under which it presumably still works. Old versions of R are available on CRAN. or (2) rebuild and install the old package from source: Rcmd INSTALL mypackage_1.1-1.tar.gz If R has changed so much that it will no longer build, install or run under the latest version of R then you will need to fix up the source code and rebuild and reinstall the package. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.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] Uncertainty propagation
Thanks a lot for the help, I linearized my power relations en fitted them with a linear rlm() function. When I re-sample my pairs from a bivariate normal distribution for my power law what transformation do I need to apply a transformation to my covariance (vcov) matrix to get back from my linearized regression to my power law space. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Uncertainty-propagation-tp2713499p2714549.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] Good documentation about Sweave
Colin Some links I used to get me going ... http://www.ics.uci.edu/~vqnguyen/talks/SweaveSeminaR.pdf http://www.r-bloggers.com/getting-started-with-sweave-r-latex-eclipse-statet-texlipse/ http://www.statistik.lmu.de/~leisch/Sweave/ http://stat.epfl.ch/webdav/site/stat/shared/Regression/EPFL-Sweave-powerdot.pdf http://www.biostat.jhsph.edu/~rpeng/ENAR2009/lecture-slides.pdf HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Good-documentation-about-Sweave-tp2714326p2714560.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] Newbie Correspondence Analysis Question
Thanks very much. -Vik On Sep 26, 2010, at 9:45 AM, Chris Mcowen wrote: Have you loaded the library after installing it? Either use library(CA) Or Through the package manager tab Hth Sent from my iPhone On 26 Sep 2010, at 17:41, Vik Rubenfeld v...@mindspring.com wrote: I'm experienced in statistics, but I am a first-time R user. I would like to use R for correspondence analysis. I have installed R (Mac OSX). I have used the package installer to install the CA package. I have run the following line with no errors to read in the data for a table: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) The R online help appears to suggest that the following line should come next: corresp(NonLuxury) However, I get the error message: Error: could not find function corresp The CA manual appears to suggest that the following line should come next: ca(NonLuxury) Again, I get the error message: Error: could not find function ca What am I missing? Thanks very much in advance to all for any info. -Vik __ 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] Storing CA Results to a Data Frame?
I am successfully performing a correspondence analysis using the commands: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) ca(NonLuxury) I would like to store the results to a data frame so that I can write them to disk using write.table. I have tried several things such as: df - data.frame(ca(NonLuxury)) df - data.frame(data(ca(NonLuxury))) etc. ...but clearly this is incorrect as it generates an error message. Is it possible to store the results of a CA to a dataframe, and if so, what is the correct way to do this? Thanks in advance to all for any info. -Vik __ 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] Good documentation about Sweave
Hello On Sun, Sep 26, 2010 at 3:41 PM, statquant2 statqu...@gmail.com wrote: I am looking for a good and detailed documentation about Sweave... but can't find anything more that 15 pages asking Google... Any hint on that point ? In the search below the third link is the user manual, which should contain enough information to get you started. Other than various examples and miscellaneous tips, I don't think that you'll find more comprehensive documentation. http://www.google.fr/search?client=operarls=enq=sweavesourceid=operaie=utf-8oe=utf-8 You may also want to look at this page [1] by Frank Harrell with info on reproducible reports in R. Regards Liviu [1] http://biostat.mc.vanderbilt.edu/wiki/Main/statReport __ 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] Storing CA Results to a Data Frame?
[Sorry- somehow the first time I posted this it got attached to another thread -Vik] I am successfully performing a correspondence analysis using the commands: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) ca(NonLuxury) I would like to store the results to a data frame so that I can write them to disk using write.table. I have tried several things such as: df - data.frame(ca(NonLuxury)) df - data.frame(data(ca(NonLuxury))) etc. ...but clearly this is incorrect as it generates an error message. Is it possible to store the results of a CA to a dataframe, and if so, what is the correct way to do this? Thanks in advance to all for any info. -Vik [[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] Storing CA Results to a Data Frame?
Hi Vik, I suggest reading through some of the introductory documentation. R has several classes of objects, including matrix, list, data.frame etc. and a basic understanding of what these are is essential for effectively using R. An essential function is str() which shows you the structure of an object. Other essential functions include names(), help(), help.search(), and methods() An example session that is similar to your case: library(ca) # load the ca package data(author) # load the authors dataset str(author) # examine the authors data auth.ca - ca(author) # run the ca function on the authors data str(auth.ca) # examin the structure of the auth.ca results. Note that it is a list with class of ca methods(class=class(auth.ca)) # see what methods are defined for this type of object ?plot.ca ## look up the documentation for the plot method for objects of class ca plot(auth.ca) ## call the plot method auth.ca.sum - summary(auth.ca) ## call the summary method str(auth.ca.sum) # examine the structure of the auth.ca.sum object methods(class=class(auth.ca.sum)) ## find out what methods are defined for it ## Hmmn ok, so suppose I want to extract the rows and columns data.frames from auth.ca.sum but don't know how help.search(extract) ## first result is base::Extract ?Extract ## look up documentation for extract auth.ca.rows - auth.ca.sum[[rows]] ## extract the rows data.frame auth.ca.rows - auth.ca.sum[[columns]] ## extract the columns data.frame write.csv(auth.ca.rows) ## write results to a .csv file write.csv(auth.ca.rows) ## HTH, Ista On Sun, Sep 26, 2010 at 6:10 PM, Vik Rubenfeld v...@mindspring.com wrote:, I am successfully performing a correspondence analysis using the commands: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) ca(NonLuxury) I would like to store the results to a data frame so that I can write them to disk using write.table. I have tried several things such as: df - data.frame(ca(NonLuxury)) df - data.frame(data(ca(NonLuxury))) etc. ...but clearly this is incorrect as it generates an error message. Is it possible to store the results of a CA to a dataframe, and if so, what is the correct way to do this? Thanks in advance to all for any info. -Vik __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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] finding big matrix size and SVD
Dear R helpers I have a big data sheet (CSV) which I use âread.csvâ to read it When im trying to get the Dim() it says 38 column which is not correct it should be something about 400. I am wondering whether there is any way I can read it right⦠I have used ncol() and itâs the same answer On the other hand I use to get the SVD of it but I have about 500,000 rows so considering that it should be rectangular matrix⦠im wondering how this can be possible Natasha [[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] plot single part of the country using gadm map
Dear all, in GADM map there are three levels (nation, province and precinct) for each country of the world but for all of them you are never able to plot only one part of a chosen country. To be sure, I am trying to plot only one region of Italy and colour the different precincts in it. So far I am able to colour only the part of my interest but the programme still plot the whole country. Is that a way to have only a chosen part of the country (ie. region or state) with all the specific subunits in it? I have tried also to plot and then zoom but the zoom function seems to work only with plot while gadm map uses spplot. Anyone knows if the zoom command works also with spplot? Any suggestions? Thank you very much. Carolina -- Carolina Plescia PhD Candidate and IRCHSS Scholar Department of Political Science Institute for International Integration Studies Trinity College Dublin plesc...@tcd.ie [[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] the function doesn´t work
Dear Kaja, I've read quite a few of your emails and spent some time trying to understand what you want, and so have a lot of other people. I know this must be very frustrating for you especially because you have a deadline soon. I have noticed that in your emails, your explanations of what you are trying to do are very similar, and for whatever reason, it does not seem to be making sense to everyone on R-help. Since sending us the code you (and others) have written has not been working, I think it is time for a change. Three options come to mind. 1) Try to find someone near you to help (perhaps your thesis advisor, a professor you know, a graduate student, etc.). Many people in academia use R and there are quite a few useR groups. Also, many universities have a statistical consulting center where you may be able to seek some advice and help. 2) Assuming that there is some formula or set of calculations you are trying to have R do, can you show us what these are? Most word processors as well as LaTeX can typeset mathematical formulae, which you could save to a PDF and upload online. If we could see these, perhaps we could point out what part of your code/function does not match. If you take this option, be sure to define what all the variables are. 3) Another way would be to create a very simple dataset, and show all the calculations you want done by hand. For example, given the vectors x = [1 3 2 4]y = [1 2 3 4] (I made this up, but you should pick data that will work), what final result would you expect from your function? Knowing this would make it possible to evaluate the results of your code and figure out why it differs from what you need it to be. Right now, we can point to other functions you could try, or make little changes to your code 'till the cows come home (an Americanism, I believe, at any rate, it means for a long time) and not get anywhere. Best wishes, Josh On Sun, Sep 26, 2010 at 12:57 AM, jethi kart...@hotmail.com wrote: i´m really sorry, once again. ok i will try to explain what i have to programm. i want to programm a powerfunction. i have to research if the correlations in a bivariate random sample are homogeneous. for that i saperate the random sample in m blocks and calculate the correlation of each block(partial sample). than i look at the random variable p=cor(x1,y1)^2/sum(cor(x,y)^2) which is a probability. my null hypothesis is that all correlations are homogeneous. if we have this situation the entropy take the value log(m). my test based on the entropy. so my teststatic is H=log(m)-sum(p*log(p)). the following programm was actually, which i have worked the most of the time. i hope that i don´t confuse u too much. i of course i hope u understand my problem and my theme. n=1000 m=2 k=n/m N=100 myfun - function(n, m, alpha = .05, seeder = 1000) { l=matrix(0,nrow=m,ncol=N) for(i in 1:N){ set.seed(i) for(j in 1:m){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } gute - function(x,m) { q_1 - qnorm(alpha, 0, 0.05) q_2 - qnorm(1 - alpha, 0, 0.05) p=matrix(0,nrow=m,ncol=N) H=matrix(0,nrow=N,ncol=1) for(i in 1:N){ for (j in 1:m){ p[j,i]=x[j]^2/sum(x[,i]^2) } H[i]=log(m)-sum(p[,i]*log(p[,i])) } 1 - mean(q_1 = H H = q_2) } output - gute(x = l,m=m) return(output) } -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714137.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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] Uncertainty propagation
Maayt m.lupker at hotmail.com writes: I linearized my power relations en fitted them with a linear rlm() function. When I re-sample my pairs from a bivariate normal distribution for my power law what transformation do I need to apply a transformation to my covariance (vcov) matrix to get back from my linearized regression to my power law space. Thanks rlm() does return a fitted model object that 'inherits from' (is a variant/superset of) the 'lm' class, therefore vcov(modelfit) should work (but see caution below). You should 'unpack' the results in the opposite direction from your modeling -- simulate on the linearized scale, then invert the transformation you used in order to get the curves back to your 'power law space'. The caution is that without digging into the details of rlm() [and reading the appropriate section of Venables and Ripley], I don't know whether the vcov() matrix based on robust regression will preserve the non-Gaussian characteristics of your data ... you may find when you do the simulations that they do *not* capture the variance of your data appropriately, because the robust part of 'robust linear modeling' deliberately downweights the effects of outliers. You may find that your results look plausible anyway. If not, this begins to turn (for me anyway) into a non-trivial problem. One possibility (although more time-consuming) would be to (nonparametrically) bootstrap the data, and generate a predicted curve for each bootstrap sample -- then use the envelope of these bootstrapped curves to characterize the uncertainty (in general this would be a little bit more robust/general/parsimonious than the 'prediction interval' approach I've suggested, although more computationally intensive and slightly harder to set up). __ 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] the function doesn´t work
thanks a lot for ur patience and understandig, josh. ok perhaps it would be help me to change my programm by step by step. the first important thing of my programm is to caluculate the correlation of each block of a radom variable. so i have a n bivariate random sample wich i saperate in m blocks and calculate the correlation. i designe a matrix for that. so that i watch not one n bivariate random sample, but N bivariate random sample. (its important to watch a matrix because for my powerfunction later) so i programm my correlationfunction like that N=10 n=100 m=5 k=n/m l=matrix(0,nrow=m,ncol=N) for(i in 1:N){ for(j in 1:m){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) l l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } i think their is a mistake, am i right? if i watch this matrix, i don´t exactliy know which correlations are to which random sample, do i? i hope u have still time to help me. regards jethi -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714702.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] the function doesn´t work
Hi, You are correct that you do not know what the correlations are from exactly. I tried to make up some examples to show you why. ## Your Code N = 10 n = 100 m = 5 k = n/m l = matrix(0,nrow=m,ncol=N) for(i in 1:N){ for(j in 1:m){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) ## inside for loops you need the print() command ## explicity if you want to see it ## Warning that this will create a lot of output print(l) l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } # Let's break this down a bit to make it more understandable # First we do all the setup, straight forward enough N = 10 n = 100 m = 5 k = n/m l = matrix(0, nrow=m, ncol=N) # Now the for loops # Ignoring the outer one (for simplicity) you have for(j in 1:m){ ## rnorm() is called m times for both x and y ## which means every pass through the loop, ## their values will be different x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) ## This just prints the values of l so far print(l) ## this assigns the results of the call to cor() to a particular ## cell in the matrix l l[j,i] = cor( ## You are finding the correlation between a subset of ## x and y values (based on the current values of i and j ## BUT, x and y themselves are changing everytime ## so what you are actually doing is taking a random sample ## and then taking a non-random subsample from this ## which should just work out to be a smaller random sample (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)]) ) } # Another way to look at this that might make it a bit clearer # Going back to your full code N = 10 n = 100 m = 5 k = n/m l = matrix(0,nrow=m,ncol=N) ## create another matrix with same dimensions as l vals = matrix(0, nrow = m, ncol = N) for(i in 1:N){ for(j in 1:m){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) ## create an object storing what values ## you are selecting (so we can see it later) vals[j, i] = pastej-1)*k)+1), (((j-1)*k)+k), sep = :) l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } ## now we can print the matrix of correlations ## and the the numbers used to subset them ## This lends some insight into the subsets being used ## but as I mentioned before, x and y are changing each time vals l # One way to get around this, would be to assign x and y # outside of your for loop # For instance, lets say you wanted to regenerate x and y only # for each column (rather than for every single correlation) # This makes some sense given the subsets you select # are unique within a column, but not across rows N = 10 n = 100 m = 5 k = n/m l = matrix(0,nrow=m,ncol=N) ## outer loop for(i in 1:N){ ## I have moved the assignment into the outer loop ## now x and y will only be regenerated N times ## rather than N * m times x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) ## inner loop for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } l # print matrix of correlations ## HTH, Josh On Sun, Sep 26, 2010 at 1:50 PM, jethi kart...@hotmail.com wrote: thanks a lot for ur patience and understandig, josh. ok perhaps it would be help me to change my programm by step by step. the first important thing of my programm is to caluculate the correlation of each block of a radom variable. so i have a n bivariate random sample wich i saperate in m blocks and calculate the correlation. i designe a matrix for that. so that i watch not one n bivariate random sample, but N bivariate random sample. (its important to watch a matrix because for my powerfunction later) so i programm my correlationfunction like that N=10 n=100 m=5 k=n/m l=matrix(0,nrow=m,ncol=N) for(i in 1:N){ for(j in 1:m){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) l l[j,i]=cor((x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } i think their is a mistake, am i right? if i watch this matrix, i don´t exactliy know which correlations are to which random sample, do i? i hope u have still time to help me. regards jethi -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714702.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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] the function doesn´t work
thnx again. now i understand my big problem. ok so now a want to watch the probabilities p, which are do this for example p[1,1]=cor(x1,y1)/(cor(x1,y1)+..+cor(xm,ym)). so N = 10 n = 100 m = 2 k = n/m l = matrix(0,nrow=m,ncol=N) p=matrix(0,nrow=m,ncol=N) for(i in 1:N){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } for(i in 1:N){ for (j in 1:m){ p[j,i]=l[j,i]^2/sum(l[,i]^2) } } i didn´t write the matrix in the first loop with l, because if i do that, he takes at first only the first value. and then the first and the second value of l. so its wrong. because of it i take a new two loops which make exactly what i want. regards jethi -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714755.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] the function doesn´t work
On Sun, Sep 26, 2010 at 3:16 PM, jethi kart...@hotmail.com wrote: thnx again. now i understand my big problem. ok so now a want to watch the probabilities p, which are do this for example p[1,1]=cor(x1,y1)/(cor(x1,y1)+..+cor(xm,ym)). so N = 10 n = 100 m = 2 k = n/m l = matrix(0,nrow=m,ncol=N) p=matrix(0,nrow=m,ncol=N) for(i in 1:N){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } for(i in 1:N){ for (j in 1:m){ p[j,i]=l[j,i]^2/sum(l[,i]^2) } } i didn´t write the matrix in the first loop with l, because if i do that, he takes at first only the first value. and then the first and the second value of l. so its wrong. This is true, it sounds like you're starting to get a better feel for what is happening. Just as another option, you can use the apply() function to apply something to each column of a matrix, for instance: ## it uses the function apply() to apply to each column of l ## my simple function(z) which squares each element of z and divides ## by the sum of squares p2 - apply(l, 2, function(z) {(z^2)/sum(z^2)}) ## verify that the for loop and apply method produce identical results identical(p, p2) You would still have to do this after you had completely calculated all of the correlations. because of it i take a new two loops which make exactly what i want. So is everything working for you now? regards jethi -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714755.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] Survival graph and tables
Hi, I'm trying to make such a graphic : http://heart.bmj.com/content/96/9/662/F1.large.jpg Hi, I finally managed with the survplot function from the Design package. The only thing I could not achieve was to place the number of patient at risk under the x-axis. Does somebody know how to do that ? TIA Blaise __ 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] Problem with unlist
Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.3 So I would like to get for each element of the list the element called Pluv3Meses. The whole list has 5065 elements but when I try to unlist it I am getting 5081 elements I don't know why: length(unlist(sapply(SumaPluvi,[,1))) [1] 5081 Does anybody know what can be happening? Thank You Felipe Parra __ 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] Split Split Plot with aov function R
*Hello,* * * *I'm new to R and trying to do Split Split Plot Design analysis with aov function in R. Sharing any worked example and suggestion will be highly appreciated. Thanks* * * *Regards! * -- * Muhammad Yaseen * [[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] Problem with unlist
My guess is that some of the Pluv3Meses elements have more than one value. Have you checked your data to see if this is the case? On Sun, Sep 26, 2010 at 7:12 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.3 So I would like to get for each element of the list the element called Pluv3Meses. The whole list has 5065 elements but when I try to unlist it I am getting 5081 elements I don't know why: length(unlist(sapply(SumaPluvi,[,1))) [1] 5081 Does anybody know what can be happening? Thank You Felipe Parra __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] CRAN (and crantastic) updates this week
CRAN (and crantastic) updates this week New packages Updated packages BioPhysConnectoR (1.6-6), Deducer (0.4-1) This email provided as a service for the R community by http://crantastic.org. Like it? Hate it? Please let us know: crana...@gmail.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] Problem with unlist
Hi Felipe, Could it be something like what happens in mylist2? ### mylist - list(1:4, 2:5, 3:6) mylist2 - list(list(1:4, 11:14), 2:5, 3:6) length(unlist(sapply(mylist, [, 1))) length(unlist(sapply(mylist2, [, 1))) ### HTH, Josh On Sun, Sep 26, 2010 at 4:12 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.3 So I would like to get for each element of the list the element called Pluv3Meses. The whole list has 5065 elements but when I try to unlist it I am getting 5081 elements I don't know why: length(unlist(sapply(SumaPluvi,[,1))) [1] 5081 Does anybody know what can be happening? Thank You Felipe Parra __ 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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.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] Problem with unlist
x - lapply(SumaPluvi, FUN=[, 1); n - sapply(x, FUN=length); print(table(n)); print(which(n != 1)); My $.02 /H On Sun, Sep 26, 2010 at 4:12 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.3 So I would like to get for each element of the list the element called Pluv3Meses. The whole list has 5065 elements but when I try to unlist it I am getting 5081 elements I don't know why: length(unlist(sapply(SumaPluvi,[,1))) [1] 5081 Does anybody know what can be happening? Thank You Felipe Parra __ 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] the function doesn´t work
hi josh, and really thnx again. i have now 2 problems . the first one ist if i take ur idea and programm like u: N = 10 n = 100 m = 2 k = n/m l = matrix(0,nrow=m,ncol=N) p=matrix(0,nrow=m,ncol=N) alpha = 0.05 q_1 - qnorm(alpha, 0, 0.05) q_2 - qnorm(1 -alpha, 0, 0.05) for(i in 1:N){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } for(i in 1:N){ for (j in 1:m){ p[j,i]=l[j,i]^2/sum(l[,i]^2) } } p2 - apply(l, 2, function(z) {(z^2)/sum(z^2)}) identical(p, p2) H=matrix(0,nrow=N,ncol=1) for(i in 1:N){ H[i]=log(m)-sum(p[,i]*log(p[,i])) } H1-apply(p2,2,function(t){(log(m)-sum(t*log(t)))}) identical(H1, H) it gives me, that identical(H1, H) is False. is it because of H? H is a matrix and H1 is a list, isn´t it? ok if i leave H1 out and programm further to get my powerfunction, it gives me always the value 1. even i change my alpha or the number of n, m or N.: N = 10 n = 100 m = 2 k = n/m l = matrix(0,nrow=m,ncol=N) p=matrix(0,nrow=m,ncol=N) alpha = 0.05 q_1 - qnorm(alpha, 0, 0.05) q_2 - qnorm(1 -alpha, 0, 0.05) for(i in 1:N){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } for(i in 1:N){ for (j in 1:m){ p[j,i]=l[j,i]^2/sum(l[,i]^2) } } p2 - apply(l, 2, function(z) {(z^2)/sum(z^2)}) identical(p, p2) H=matrix(0,nrow=N,ncol=1) for(i in 1:N){ H[i]=log(m)-sum(p[,i]*log(p[,i])) } 1-mean(q_1=H H =q_2) regards jethi -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714815.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] Normalizing Vector with Negative Numbers
Dear expert, I have a series of number that looks like this x - c(-0.005282, 0.000314, 0.002851, -2.5059217162, -0.007545, -1.0317758496, 0.001598, -1.2981735068, 0.072411) How can I normalize it in R so that the new numbers is ranging from 0 to 1 ? - G.V. __ 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] Changing x-axis on boxplot
Tim, Boxplots are nice, but I find that they can be somewhat misleading when applied to small groups, especially in the suggestion of spread differences. (Your real data may well be more extensive than the ToothGrowth data and so the following may be moot.) I prefer stripcharts for small groups. Compare the boxplot figure to the following (using Dennis's code as basis): stripchart(len ~ dose, data = subset(ToothGrowth, supp == 'VC'), method = jitter, jitter = .03, vertical = TRUE, at = 1:3 - 0.1, pch = 21, bg = yellow, cex = 1.5, main = Guinea Pigs' Tooth Growth, axes = FALSE, xlab = Vitamin C dose mg, ylab = Tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i) stripchart(len ~ dose, data = subset(ToothGrowth, supp == 'OJ'), add = TRUE, method = jitter, jitter = .03, vertical = TRUE, at = 1:3 + 0.1, axes = FALSE, pch = 21, bg = orange, cex = 1.5) axis(1, at = 1:3, labels = c(0.5, 1, 2)) axis(2) box() legend(2, 9, c(Ascorbic acid, Orange juice), pch = 21, pt.bg = c(yellow, orange), pt.cex = 1.5) -Peter Ehlers On 2010-09-26 4:48, Dennis Murphy wrote: Hi: Here are a couple of ways: (1) Base graphics: add argument axes = FALSE to both plots, then add axes boxplot(len ~ dose, data = subset(ToothGrowth, supp == 'VC'), boxwex = 0.25, at = 1:3 - 0.2, col = yellow, main = Guinea Pigs' Tooth Growth, axes = FALSE, xlab = Vitamin C dose mg, ylab = Tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i) boxplot(len ~ dose, data = subset(ToothGrowth, supp == 'OJ'), add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, axes = FALSE, col = orange) axis(1, at = 1:3, labels = c(0.5, 1, 2)) axis(2) legend(2, 9, c(Ascorbic acid, Orange juice), fill = c(yellow, orange)) box() (2) ggplot2 (just for fun :) library(ggplot2) g- ggplot(ToothGrowth, aes(x = factor(dose), y = len)) g + geom_boxplot(aes(fill = supp), position = position_dodge(width = 0.9)) + scale_fill_manual('', breaks = c('OJ', 'VC'), values = c('orange', 'yellow'), labels = c('Orange juice', 'Ascorbic acid')) + theme_bw() + opts(legend.position = c(0.8, 0.2), legend.text = theme_text(size = 12)) + opts(panel.grid.major = theme_blank()) + xlab('Vitamin C dose (mg)') + ylab('Tooth length') + opts(title = Guinea pigs' tooth growth) + opts(plot.title = theme_text(size = 16)) HTH, Dennis On Sat, Sep 25, 2010 at 11:13 PM, Tim Clarkmudiver1...@yahoo.com wrote: Dear List, I am creating a boxplot with two subsets, very similar to the example by Roger Bivand at ?boxplot (reproduced below). I am trying to change the labels on the x-axis to have one number to cover both subsets. I can do this in other plots by using axis=FALSE followed by a separate axis() command. I have also tried variations in the names= argument but can't get it to work. Ideally I would like tickmarks on either side of each factor with the number for the level centered between the two tick marks. Any suggestions? Thanks, Tim Example: boxplot(len ~ dose, data = ToothGrowth, boxwex = 0.25, at = 1:3 - 0.2, subset = supp == VC, col = yellow, main = Guinea Pigs' Tooth Growth, xlab = Vitamin C dose mg, ylab = tooth length, xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = i) boxplot(len ~ dose, data = ToothGrowth, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2, subset = supp == OJ, col = orange) legend(2, 9, c(Ascorbic acid, Orange juice), fill = c(yellow, orange)) Tim Clark Marine Ecologist National Park of American Samoa __ 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] Normalizing Vector with Negative Numbers
Is the what you want: x [1] -0.005282 0.000314 0.002851 -2.5059217162 -0.007545 -1.0317758496 0.001598 [8] -1.2981735068 0.072411 (x-min(x))/(max(x) - min(x)) [1] 0.969 0.971 0.972 0.000 0.968 0.5882632 0.972 0.4819563 1.000 On Sun, Sep 26, 2010 at 8:22 PM, Gundala Viswanath gunda...@gmail.com wrote: Dear expert, I have a series of number that looks like this x - c(-0.005282, 0.000314, 0.002851, -2.5059217162, -0.007545, -1.0317758496, 0.001598, -1.2981735068, 0.072411) How can I normalize it in R so that the new numbers is ranging from 0 to 1 ? - G.V. __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Problem with unlist
x - lapply(SumaPluvi, FUN=[, 1); y - lapply(x, FUN=unlist); # == n - sapply(y, FUN=length); print(table(n)); print(which(n != 1)); /Henrik On Sun, Sep 26, 2010 at 7:02 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Henrik, thank you for your help, but I tried your code, and this is what I get x - lapply(SumaPluvi, FUN=[, 1); n - sapply(x, FUN=length); print(table(n)); n 1 5065 print(which(n != 1)); integer(0) length(unlist(lapply(SumaPluvi, FUN=[, 1))) [1] 5081 apparently the problem is still there if I use lapply, I dont now why, but when I unlist it the number of elements changes from 5065 to 5084 if there is no list element with length greater than one. Do you know what can be happening? Thank you Felipe Parra On Mon, Sep 27, 2010 at 8:05 AM, Henrik Bengtsson h...@stat.berkeley.edu wrote: x - lapply(SumaPluvi, FUN=[, 1); n - sapply(x, FUN=length); print(table(n)); print(which(n != 1)); My $.02 /H On Sun, Sep 26, 2010 at 4:12 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.3 So I would like to get for each element of the list the element called Pluv3Meses. The whole list has 5065 elements but when I try to unlist it I am getting 5081 elements I don't know why: length(unlist(sapply(SumaPluvi,[,1))) [1] 5081 Does anybody know what can be happening? Thank You Felipe Parra __ 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] the function doesn´t work
Hi Jethi, Please look at this code, and the graph that is created in the code. This all leads me to suspect you are trying to use the wrong formula at the end. Since there was some confusion with it, I just removed the stuff with apply(). Josh ## I moved stuff around to assign all global variables at the beginning ## Assign global variables; this works N = 10 n = 100 m = 2 k = n/m l = matrix(0, nrow=m, ncol=N) p = matrix(0, nrow=m, ncol=N) H = matrix(0, nrow=N, ncol=1) alpha = 0.05 q_1 - qnorm(alpha, 0, 0.05) q_2 - qnorm(1 - alpha, 0, 0.05) ## Calculate correlations; this works for(i in 1:N){ x = rnorm(n,0,0.5) y = rnorm(n,0,0.8) for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } ## Calculate probabilities; this works for(i in 1:N){ for (j in 1:m){ p[j,i] = (l[j,i]^2) / sum(l[,i]^2) } } ## Calculate this other thing; this works, but is not what you want for(i in 1:N){ H[i]=log(m)-sum(p[,i]*log(p[,i])) } 1 - mean(q_1 = H H = q_2) ## lets break this down then, and see what each part does ## first we are going to redefine H. H = log(m) - zz ## where zz = sum(p[,i] * log(p[,i])) ## create the matrix zz zz - matrix(0, nrow=N, ncol=1) for(i in 1:N) { zz[i] - sum(p[,i] * log(p[,i])) } ## You have a logical test (q_1 = H = q_2) ## that is true when H is between q_1 and q_2 ## Lets plot our data to see what is going on plot(x = seq_along(zz), y = zz, ylim = c(-1, 2), col = black, pch = 16) points(x = seq_along(zz), y = H, col = blue, pch = 16) abline(h = q_1, col = red) abline(h = q_2, col = red) abline(h = log(m), col = green) ## The black dots are the values of zz (sum(p[,i] * log(p[,i]))) ## the blue dots are your actual values of H ## the red lines are the region selected by q_1 and q_2 (based on alpha) ## for your logical test to evaluate TRUE, the blue dots MUST be within the red lines ## otherwise it will be FALSE ## finally, the green line is log(m), you can see that log(m) is so far outside ## of the selection region (between red lines), that it pushes ## every sum(p[,i] * log(p[,i])) outside ## To change this, you need to lower log(m) (~ m = .8 would work) ## or you need to increase sum(p[,i] * log(p[,i])), which is tricky ## because log(1) = 0, and the log of anything in the interval (0, 1) ## is a negative number. If p is a probability, it must be between [0, 1] ## which means you are guaranteed to be multiplying a positive number by ## a negative number, or 0. This in turn means the sum of all of these ## will itself be negative, or 0. So, since H = log(m) - zz, and we have ## established that zz must be 0 or negative, the minimum bound of H is log(m) ## and you can see from the graph (log(m) is the green line), that log(m) ## is far above your selection region # On Sun, Sep 26, 2010 at 5:13 PM, jethi kart...@hotmail.com wrote: hi josh, and really thnx again. i have now 2 problems . the first one ist if i take ur idea and programm like u: N = 10 n = 100 m = 2 k = n/m l = matrix(0,nrow=m,ncol=N) p=matrix(0,nrow=m,ncol=N) alpha = 0.05 q_1 - qnorm(alpha, 0, 0.05) q_2 - qnorm(1 -alpha, 0, 0.05) for(i in 1:N){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } for(i in 1:N){ for (j in 1:m){ p[j,i]=l[j,i]^2/sum(l[,i]^2) } } p2 - apply(l, 2, function(z) {(z^2)/sum(z^2)}) identical(p, p2) H=matrix(0,nrow=N,ncol=1) for(i in 1:N){ H[i]=log(m)-sum(p[,i]*log(p[,i])) } H1-apply(p2,2,function(t){(log(m)-sum(t*log(t)))}) identical(H1, H) it gives me, that identical(H1, H) is False. is it because of H? H is a matrix and H1 is a list, isn´t it? ok if i leave H1 out and programm further to get my powerfunction, it gives me always the value 1. even i change my alpha or the number of n, m or N.: N = 10 n = 100 m = 2 k = n/m l = matrix(0,nrow=m,ncol=N) p=matrix(0,nrow=m,ncol=N) alpha = 0.05 q_1 - qnorm(alpha, 0, 0.05) q_2 - qnorm(1 -alpha, 0, 0.05) for(i in 1:N){ x=rnorm(n,0,0.5) y=rnorm(n,0,0.8) for(j in 1:m){ l[j,i] = cor( (x[(((j-1)*k)+1):(((j-1)*k)+k)]), (y[(((j-1)*k)+1):(((j-1)*k)+k)])) } } for(i in 1:N){ for (j in 1:m){ p[j,i]=l[j,i]^2/sum(l[,i]^2) } } p2 - apply(l, 2, function(z) {(z^2)/sum(z^2)}) identical(p, p2) H=matrix(0,nrow=N,ncol=1) for(i in 1:N){ H[i]=log(m)-sum(p[,i]*log(p[,i])) } 1-mean(q_1=H H =q_2) regards jethi -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714815.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,
Re: [R] finding big matrix size and SVD
Hi, On Sun, Sep 26, 2010 at 12:42 PM, Natasha Asar natasha.asa...@yahoo.com wrote: Dear R helpers I have a big data sheet (CSV) which I use “read.csv” to read it When im trying to get the Dim() it says 38 column which is not correct it should be something about 400. I am wondering whether there is any way I can read it right… I have used ncol() and it’s the same answer It seems that perhaps the input file isn't well formed, and R can't correctly identify that each row should have 400 columns? Maybe you can try to read it in manually (using readLines, for instance), and strsplit each line so that you can get finer control of reading the file. Alternatively, you can try and edit the file by hand to fix it. On the other hand I use to get the SVD of it but I have about 500,000 rows so considering that it should be rectangular matrix… im wondering how this can be possible I don't follow this part, sorry ... what's the question here? -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ 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] the function doesn´t work
wow thnx a lot josh. so now i understand the most of the things. so my power function is depent on the number of the blocks m. how u said, if i take m=0.8 or lower i get a different value than a 1. ofcourse a number between 0 or 1. but i can just take positive interger number for m, because m representet die value for the blocks and they could be only a positiv number. moreover the graphic show that my H will never reach log(m) because like u said p are probilities. so if i would now plot the powerfunction for different m(positiv integer), the graph would be a constant value. am i right? thank u very very much. its help me a lot. -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714875.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] IRT ltm function plot for probabilities
Hello, my question is; for a specific item, how can I create a plot with both the empirical probability of correct response and the predicted probability as a function of the mean of the ability intervals (similar to a BILOG plot). Thank you -- View this message in context: http://r.789695.n4.nabble.com/IRT-ltm-function-plot-for-probabilities-tp2714881p2714881.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] Storing CA Results to a Data Frame?
Thanks very much for this great info, Ista. Best, -Vik On Sep 26, 2010, at 12:10 PM, Ista Zahn wrote: Hi Vik, I suggest reading through some of the introductory documentation. R has several classes of objects, including matrix, list, data.frame etc. and a basic understanding of what these are is essential for effectively using R. An essential function is str() which shows you the structure of an object. Other essential functions include names(), help(), help.search(), and methods() An example session that is similar to your case: library(ca) # load the ca package data(author) # load the authors dataset str(author) # examine the authors data auth.ca - ca(author) # run the ca function on the authors data str(auth.ca) # examin the structure of the auth.ca results. Note that it is a list with class of ca methods(class=class(auth.ca)) # see what methods are defined for this type of object ?plot.ca ## look up the documentation for the plot method for objects of class ca plot(auth.ca) ## call the plot method auth.ca.sum - summary(auth.ca) ## call the summary method str(auth.ca.sum) # examine the structure of the auth.ca.sum object methods(class=class(auth.ca.sum)) ## find out what methods are defined for it ## Hmmn ok, so suppose I want to extract the rows and columns data.frames from auth.ca.sum but don't know how help.search(extract) ## first result is base::Extract ?Extract ## look up documentation for extract auth.ca.rows - auth.ca.sum[[rows]] ## extract the rows data.frame auth.ca.rows - auth.ca.sum[[columns]] ## extract the columns data.frame write.csv(auth.ca.rows) ## write results to a .csv file write.csv(auth.ca.rows) ## HTH, Ista On Sun, Sep 26, 2010 at 6:10 PM, Vik Rubenfeld v...@mindspring.com wrote:, I am successfully performing a correspondence analysis using the commands: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) ca(NonLuxury) I would like to store the results to a data frame so that I can write them to disk using write.table. I have tried several things such as: df - data.frame(ca(NonLuxury)) df - data.frame(data(ca(NonLuxury))) etc. ...but clearly this is incorrect as it generates an error message. Is it possible to store the results of a CA to a dataframe, and if so, what is the correct way to do this? Thanks in advance to all for any info. -Vik __ 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ 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] the function doesn´t work
As long as p = 1, the minimum value of H will be log(m). Here are some more (I think clearer) graphs. They show the basic function p[,i] * log(p[,i] (the log function defaults to natural logarithm), for values ranging from 0 to 1. Then include log(m) for different values of m. I included the code, and also attached a PDF in incase there was any trouble running the code. x - seq(0, 1, by = .01) par(mfrow = c(3, 2)) plot(x = x, y = log(x ^ x), type = l, ylab = bquote(f(x) == ln(x^x)), main = Basic graph) plot(x = x, y = -log(x ^ x), type = l, ylab = bquote(f(x) == -ln(x^x)), main = Basic negative graph) plot(x = x, y = log(0.5) - log(x ^ x), type = l, ylab = bquote(f(x) == ln(0.5) - ln(x^x)), main = m = 0.5) plot(x = x, y = log(1) - log(x ^ x), type = l, ylab = bquote(f(x) == ln(1) - ln(x^x)), main = m = 1) plot(x = x, y = log(2) - log(x ^ x), type = l, ylab = bquote(f(x) == ln(2) - ln(x^x)), main = m = 2) plot(x = x, y = log(6) - log(x ^ x), type = l, ylab = bquote(f(x) == ln(6) - ln(x^x)), main = m = 6) So the way I see it, you have 3 ways to get different values: 1) Increase your matrix p 2) Decrease m 3) Increase your selection region (this in turn depends on alpha, the mean, and the standard deviation) Cheers, Josh On Sun, Sep 26, 2010 at 7:58 PM, jethi kart...@hotmail.com wrote: wow thnx a lot josh. so now i understand the most of the things. so my power function is depent on the number of the blocks m. how u said, if i take m=0.8 or lower i get a different value than a 1. ofcourse a number between 0 or 1. but i can just take positive interger number for m, because m representet die value for the blocks and they could be only a positiv number. moreover the graphic show that my H will never reach log(m) because like u said p are probilities. so if i would now plot the powerfunction for different m(positiv integer), the graph would be a constant value. am i right? thank u very very much. its help me a lot. -- View this message in context: http://r.789695.n4.nabble.com/the-function-doesn-t-work-tp2714105p2714875.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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ graphs.pdf Description: Adobe PDF document __ 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] Storing CA Results to a Data Frame?
Please provide a reproducible example, like: library(ca) data(author) p - ca(author) # now look at this: str(p) to find that this object of class 'ca' has lots of different results in it - it is up to you to decide which ones you make into a dataframe. cheers, Remko -- View this message in context: http://r.789695.n4.nabble.com/Storing-CA-Results-to-a-Data-Frame-tp2714619p2714893.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] matrix help
I think you want ?solve ... Remko -- View this message in context: http://r.789695.n4.nabble.com/matrix-help-tp2714378p2714896.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] Adding row name to dataframe
Dear all, I am trying to add a value to a dataframe and name the row with a number. I have tried row.name, rowname, and attr(x,row.names) but none seem to work. It seems like it should be simple, so not sure why I can't get it to work. Any suggestions? Thanks, Tim x-seq(1,20,2) y-seq(20,1,-2) xy-data.frame(x,y) xy-rbind(xy,c(0,0)) #Threeattempts that fail row.names(xy[11,])-c(12) rownames(xy[11,])-c(12) attr(xy[11,], row.names)-c(12) Tim Clark Marine Ecologist National Park of American Samoa __ 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] a question about mgcv package
Dear all, I have a question about the basis functions of cubic regression spline in mgcv. Are there some ways I can get the exact forms of the basis functions and the penalty matrix that are used in the mgcv package? Thanks in advance! Yan PS. Sorry for sending this message twice. The header of my last message matched a filter rule, so it may not display normally. [[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] Problem with unlist
Henrik, thank you for your help, but I tried your code, and this is what I get x - lapply(SumaPluvi, FUN=[, 1); n - sapply(x, FUN=length); print(table(n)); n 1 5065 print(which(n != 1)); integer(0) length(unlist(lapply(SumaPluvi, FUN=[, 1))) [1] 5081 apparently the problem is still there if I use lapply, I dont now why, but when I unlist it the number of elements changes from 5065 to 5084 if there is no list element with length greater than one. Do you know what can be happening? Thank you Felipe Parra On Mon, Sep 27, 2010 at 8:05 AM, Henrik Bengtsson h...@stat.berkeley.eduwrote: x - lapply(SumaPluvi, FUN=[, 1); n - sapply(x, FUN=length); print(table(n)); print(which(n != 1)); My $.02 /H On Sun, Sep 26, 2010 at 4:12 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.3 So I would like to get for each element of the list the element called Pluv3Meses. The whole list has 5065 elements but when I try to unlist it I am getting 5081 elements I don't know why: length(unlist(sapply(SumaPluvi,[,1))) [1] 5081 Does anybody know what can be happening? Thank You Felipe Parra __ 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. __ 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] Problem with unlist
Hello, I am trying to unlist a list, which is attached, and I am having the problem that when I unlist it the number of elements changes from 5065 to 5084 x - lapply(SumaPluvi, FUN=[, 1); n - sapply(x, FUN=length); print(table(n)); n 1 5065 print(which(n != 1)); integer(0) length(unlist(lapply(SumaPluvi, FUN=[, 1))) [1] 5081 I dont now why, but when I unlist it the number of elements changes from 5065 to 5084 even if there is no list element with length greater than one. Do you know what can be happening? Thank you Felipe Parra On Mon, Sep 27, 2010 at 8:05 AM, Henrik Bengtsson h...@stat.berkeley.eduwrote: x - lapply(SumaPluvi, FUN=[, 1); n - sapply(x, FUN=length); print(table(n)); print(which(n != 1)); My $.02 /H On Sun, Sep 26, 2010 at 4:12 PM, Luis Felipe Parra felipe.pa...@quantil.com.co wrote: Hello I want to unlist the attached element getting only the first element in each element of the list. The last element of the list looks as this: [[5065]] [[5065]]$Pluv3Meses [1] 274.4 [[5065]]$PluvMesesMedio [1] 378.2667 [[5065]]$Pluv2UltimosMeses [1] 23.3 So I would like to get for each element of the list the element called Pluv3Meses. The whole list has 5065 elements but when I try to unlist it I am getting 5081 elements I don't know why: length(unlist(sapply(SumaPluvi,[,1))) [1] 5081 Does anybody know what can be happening? Thank You Felipe Parra __ 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. __ 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] Adding row name to dataframe
Hello Tim, Either of these variations on your example should work... rownames(xy)[11] - 12 rownames(xy)[11] - 12 It's just like assigning values to any character vector, so you can also do things like... rownames(xy) - a.vector.of.all.the.row.names rownames(xy)[1:10] - paste(foo, 1:10, sep=) Michael On 27 September 2010 12:41, Tim Clark mudiver1...@yahoo.com wrote: Dear all, I am trying to add a value to a dataframe and name the row with a number. I have tried row.name, rowname, and attr(x,row.names) but none seem to work. It seems like it should be simple, so not sure why I can't get it to work. Any suggestions? Thanks, Tim x-seq(1,20,2) y-seq(20,1,-2) xy-data.frame(x,y) xy-rbind(xy,c(0,0)) #Threeattempts that fail row.names(xy[11,])-c(12) rownames(xy[11,])-c(12) attr(xy[11,], row.names)-c(12) Tim Clark Marine Ecologist National Park of American Samoa __ 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] Adding row name to dataframe
Tim, The row names have only one dimension, so for example row.names(xy)[11]-New rname will work best, Jon -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tim Clark Sent: 27. september 2010 04:41 To: r-help@r-project.org Cc: tim_cl...@nps.gov Subject: [R] Adding row name to dataframe Dear all, I am trying to add a value to a dataframe and name the row with a number. I have tried row.name, rowname, and attr(x,row.names) but none seem to work. It seems like it should be simple, so not sure why I can't get it to work. Any suggestions? Thanks, Tim x-seq(1,20,2) y-seq(20,1,-2) xy-data.frame(x,y) xy-rbind(xy,c(0,0)) #Threeattempts that fail row.names(xy[11,])-c(12) rownames(xy[11,])-c(12) attr(xy[11,], row.names)-c(12) Tim Clark Marine Ecologist National Park of American Samoa __ 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.