Re: [R] legend for the plot with type = "b"

2013-09-22 Thread David Winsemius
On Sep 22, 2013, at 10:54 PM, Jinsong Zhao wrote: Hi there, I plot a simple plot with the following code: plot (rnorm(1:10), type = "b") legend("top", "test", lty = 1, pch = 21) ?par plot (rnorm(1:10), type = "b") legend("top", "test", lty = "69", pch = 21) The result is something wired

Re: [R] basic matrix function

2013-09-22 Thread arun
Hi, Use `drop=FALSE`.  b<- matrix(c(2,1,-1,-2),ncol=1)  b[1:3,1] #[1]  2  1 -1  b[1:3,1,drop=FALSE] #or b[1:3,,drop=FALSE] # [,1] #[1,]    2 #[2,]    1 #[3,]   -1 A.K. hi all, i got a small question tonight. > matrix(b,4)[]      [,1] [1,]    2 [2,]    1 [3,]   -1 [4,]   -2 > dim(m

Re: [R] legend for the plot with type = "b"

2013-09-22 Thread arun
Hi, May be this helps. set.seed(55)  x<-rnorm(1:10)  plot(x,type="n",xaxt="n",yaxt="n")  legend1<- legend("top","test",lty=1,pch=21) range1<- range(x)  range1[2]<- 1.05* (range1[2]+ legend1$rect$h)  plot(x,ylim=range1,type="b")  legend1<- legend("top","test",lty=1,pch=21) A.K. - Original

Re: [R] xlim with barplot

2013-09-22 Thread Jim Lemon
On 09/23/2013 01:56 PM, arun wrote: You could try ggplot() as well. library(ggplot2) library(gridExtra) library(plyr) x1<- count(x) y1<- count(y) p1<-ggplot(x1,aes(x=x,y=freq))+geom_bar(stat="identity",colour="gray",fill="red")+xlim(c(35,85))+ theme_bw()+ theme(axis.line=element_line(colour="b

Re: [R] xlim with barplot

2013-09-22 Thread arun
You could try ggplot() as well. library(ggplot2) library(gridExtra) library(plyr) x1<- count(x)  y1<- count(y) p1<-ggplot(x1,aes(x=x,y=freq))+geom_bar(stat="identity",colour="gray",fill="red")+xlim(c(35,85))+ theme_bw()+ theme(axis.line=element_line(colour="black"), panel.grid.major=element_blank(

[R] legend for the plot with type = "b"

2013-09-22 Thread Jinsong Zhao
Hi there, I plot a simple plot with the following code: plot (rnorm(1:10), type = "b") legend("top", "test", lty = 1, pch = 21) The result is something wired for the line crosses the point in the legend while the line does not cross the point in the main plot. Is there possibility to draw th

Re: [R] xlim with barplot

2013-09-22 Thread Jim Lemon
On 09/23/2013 12:55 PM, David Arnold wrote: Hi, I want to compare to barplots with same horizontal axis limits. x=c(55,56,57,58,59,60,60,60,61,62,63,64,65) y=c(35,40,45,50,55,60,60,60,65,70,75,80,85) par(mfrow=c(2,1)) barplot(table(x),xlim=c(35,85)) barplot(table(y),xlim=c(35,85)) par(mfrow=c(

Re: [R] Correlate rows of 2 matrices

2013-09-22 Thread arun
Hi, You may try: set.seed(49) m1 = matrix(rnorm(30), nrow = 3) m2 = matrix(rnorm(30), nrow = 3)  corsP<-vector()   for(i in 1:3) corsP[i] =  cor(m1[i,], m2[i,])  corsP #[1]  0.58411274 -0.02382329  0.03760757 diag(cor(t(m1),t(m2))) #[1]  0.58411274 -0.02382329  0.03760757 #or mNew<- rbind(m1,m2)

[R] xlim with barplot

2013-09-22 Thread David Arnold
Hi, I want to compare to barplots with same horizontal axis limits. x=c(55,56,57,58,59,60,60,60,61,62,63,64,65) y=c(35,40,45,50,55,60,60,60,65,70,75,80,85) par(mfrow=c(2,1)) barplot(table(x),xlim=c(35,85)) barplot(table(y),xlim=c(35,85)) par(mfrow=c(1,1)) But the bars disappear.

Re: [R] Arcsine transformation

2013-09-22 Thread peake
Thanks for the advice. Like I said, I am still pretty new to R, and stats in general. I tried wading through the search results on google, but I didn't really find anything that I could understand. I am working with percentages as my dependent variable, and I am trying to get my distribution as clo

[R] PLS1 NIPALS question: error with chemometrics package?

2013-09-22 Thread Brad P
I am doing a self study, trying to understand PLS. I have run across the following and hope that someone here can clarify as to what is going on. These are the data from Wold et al. (1984) dat <- structure(list(t = 1:15, y = c(4.39, 4.42, 5, 5.85, 4.35, 4.51, 6.33, 6.37, 4.68, 5.04, 7.1, 5.04, 6,

Re: [R] Arcsine transformation

2013-09-22 Thread Ben Bolker
On 13-09-22 09:25 PM, Peter Alspach wrote: > Tena koe > > I think you'll find the arcsine transformation is asin(sqrt(x/100)) > where × is the percentage. However, it might be better to ask > whether the data wouldn't be better analysed using generalised models > (e.g., glm). > > HTH >

Re: [R] Arcsine transformation

2013-09-22 Thread Peter Alspach
Tena koe I think you'll find the arcsine transformation is asin(sqrt(x/100)) where × is the percentage. However, it might be better to ask whether the data wouldn't be better analysed using generalised models (e.g., glm). HTH Peter Alspach -Original Message- From: r-help-boun...

Re: [R] Arcsine transformation

2013-09-22 Thread Ben Bolker
peake osu.edu> writes: > > I am tryin to perform an arcsine transformation on my data containig > percentages as the dep. variable. Does anyone have a code that I could use > to do that? I am relatively new to R. Thanks for your help! asin(x/100) ? or asin(x/100)*2/pi if you want the results

Re: [R] Conditioning plots (wth coplot function) with logistic regression curves

2013-09-22 Thread Kiyoshi Sasaki
Thank you!  Your codes produced plots that was fairly close to what I wanted. I am not familiar with ggplot2, so I need to study what exactly each code is doing. Actually, I also want to plot the observed (raw) data points (not just confidence intervals shown by ggplot, assuming that colored por

Re: [R] Creating rectangular plots with x and y coordinates and treatments from a matrix for a randomized block design

2013-09-22 Thread jim holtman
CHeck out the 'tables' package if you want to create pretty outputs of your tables. Exactly where do you plan to use them? You can also use Sweave/Latex to create such tables. Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you

[R] Arcsine transformation

2013-09-22 Thread peake
I am tryin to perform an arcsine transformation on my data containig percentages as the dep. variable. Does anyone have a code that I could use to do that? I am relatively new to R. Thanks for your help! -- View this message in context: http://r.789695.n4.nabble.com/Arcsine-transformation-tp467

Re: [R] Conditioning plots (wth coplot function) with logistic regression curves

2013-09-22 Thread Michael Friendly
On 9/21/2013 11:12 PM, Kiyoshi Sasaki wrote: I have been trying to produce a conditional plot using coplot function (http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/coplot.html) for a binary response ("Presence" in my case) variable and one continuous variable ("Overstory") given a s

Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread Ista Zahn
Hi Mosi, The easiest approach would be be generate native from re and usborn directly, rather than generating dummy codes as an intermediate step: n$native <- interaction(n[c("re", "usborn")]) This has the advantage of preserving the meanings of the levels of native in the resulting factor, so t

Re: [R] Creating rectangular plots with x and y coordinates and treatments from a matrix for a randomized block design

2013-09-22 Thread Laz
Hi, fortune("Yoda") returns a quote of fortunes. My problem was to draw horizontal and vertical lines to separate the blocks in my design. Each block has 4 elements. The first and second rows and columns are in block 1, 3rd and 4th rows and 1st and 2nd columns are in 3 etc [,1] [,2] [,

Re: [R] Creating rectangular plots with x and y coordinates and treatments from a matrix for a randomized block design

2013-09-22 Thread Rui Barradas
Hello, No, 'Yoda' is not a package, the package is 'fortunes': library(fortunes) # load it in the R session fortune("Yoda") Or, if you don't want to load the package, fortunes::fortune("Yoda") Rui Barradas Em 22-09-2013 21:32, Laz escreveu: Is "Yoda" an R package? I tried: install.packag

Re: [R] Creating rectangular plots with x and y coordinates and treatments from a matrix for a randomized block design

2013-09-22 Thread Laz
Is "Yoda" an R package? I tried: install.packages("Yoda") Warning in install.packages : package 'Yoda' is not available (for R version 3.0.1) Warning in install.packages : package 'Yoda' is not available (for R version 3.0.1) How do I proceed from here? Regards, Laz On 9/22/2013 4:21 PM,

Re: [R] Creating rectangular plots with x and y coordinates and treatments from a matrix for a randomized block design

2013-09-22 Thread Rolf Turner
On 09/23/13 07:52, Laz wrote: I was wondering if we could draw some horizontal and vertical lines to separate the blocks. Is it possible using R? See fortune("Yoda"). :-) cheers, Rolf Turner __ R-help@r-project.org mailing list https://s

Re: [R] gam and optim

2013-09-22 Thread Greg Dropkin
just to clarify how I see the error, it was the mis-definition of the penalty term in the function dv. The following code corrects this error. What is actually being minimised at this step is the penalised deviance conditional on the smoothing parameter. A second issue is that the optim default ("N

Re: [R] Creating rectangular plots with x and y coordinates and treatments from a matrix for a randomized block design

2013-09-22 Thread Laz
Thanks Jim, What you have done is very good. I was wondering if we could draw some horizontal and vertical lines to separate the blocks. Is it possible using R? Regards, Laz On 9/22/2013 11:10 AM, jim holtman wrote: Is this what you were after: ## A function to generate a RCB design rcbd<-

Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread arun
Hi, If you don't want to install any package: colnames(df1)[grep("native",colnames(df1))]<- gsub("([[:alpha:]])(\\d+)","\\1_\\2",colnames(df1)[grep("native",colnames(df1))])   df2<-reshape(df1,direction="long",varying=3:ncol(df1),sep="_")[,-5] df3<-df2[as.logical(df2$native),-4] colnames(df3)[3]<

Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread arun
Hi, Not sure this is what you wanted. df2<- melt(df1,id.vars=c("re","usborn")) df2New<-df2[df2$value==1,-4]  df2New$variable<-as.numeric(gsub("[[:alpha:]]","",df2New$variable)) colnames(df2New)[3]<- "native"  row.names(df2New)<- 1:nrow(df2New) df2New #  re usborn native #1  white    yes  0

Re: [R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread arun
Hi, Try: set.seed(385) df<- data.frame(re= sample(c("white","afam","carib"),20,replace=TRUE), usborn= sample(c("yes","no"),20,replace=TRUE),stringsAsFactors=FALSE) df1<-within(df,{native3<- 1*(re=="carib" & usborn=="no"); native2<- 1*(re=="carib" & usborn=="yes"); native1<- 1*(re=="afam" & us

[R] Coding several dummy variables into a single categorical variable

2013-09-22 Thread Mosi Ifatunji
Colleagues, I have generated several dummy variables: n$native0 <- 1 * (n$re=="white" & n$usborn=="yes") n$native1 <- 1 * (n$re=="afam" & n$usborn=="yes") n$native2 <- 1 * (n$re=="carib" & n$usborn=="yes") n$native3 <- 1 * (n$re=="carib" & n$usborn=="no") I would now like to combine these into a

Re: [R] PCA

2013-09-22 Thread Vojtěch Zeisek
Hi, see tutorial for Adegenet, http://adegenet.r-forge.r-project.org/ | Documents | adegenet-basics.pdf | section 6. It should help You. Vojtěch - Vojtěch Zeisek Department of Botany, Faculty of Science, Charles Uni., Prague, CZ Institute of Botany, Academy of Science, Czech Republic Commun

Re: [R] Obtaining data from a different row of data frame

2013-09-22 Thread arun
Ira, No problem. If you change the ?for() loop to ?lapply, there should be increase in speed (Usually, it is not the case.  Here it is does, but still not as good in terms of speed as the method I showed). df1<- structure(list(Dates = structure(c(13151, 13152, 13153, 13154,  13157, 13158, 13159,

Re: [R] Creating rectangular plots with x and y coordinates and treatments from a matrix for a randomized block design

2013-09-22 Thread jim holtman
Is this what you were after: > ## A function to generate a RCB design > > rcbd<-function(b,g,rb,cb,r,c) + { +# b =number of blocks +# g = a vector of treatments +# rb = number of rows per blocks +# cb =number of columns per block +# r = total rows +# c = total columns + li

Re: [R] Translating recoding syntax from SPSS to R

2013-09-22 Thread Mosi Ifatunji
Thanks! This worked wonderfully! Very exciting! -- Mosi On Sep 22, 2013, at 3:20 AM, Joshua Wiley wrote: Just a slight addition to Arun's answer: within() saves typing and makes life a bit easier # set.seed(429) dat1 <- data.frame( race=s

Re: [R] time zones from longitude, latitude, and date

2013-09-22 Thread Gabor Grothendieck
On Sat, Sep 21, 2013 at 10:25 AM, David Winsemius wrote: > > On Sep 21, 2013, at 3:13 AM, Prof Brian Ripley wrote: > >> On 21/09/2013 08:17, Gabor Grothendieck wrote: >>> >>> On Fri, Sep 20, 2013 at 4:31 PM, carlisle thacker >>> wrote: I was looking for something like shown on the map:

Re: [R] Setting a new method for generic function to satisfy "R CMD check"

2013-09-22 Thread Duncan Murdoch
On 13-09-21 3:30 PM, Mikhail Beketov wrote: Dear All, Can somebody explain me how to correctly set a new class-specific method for generic functions (e.g. for "plot", "summary" and "print"). I simply programmed these functions with the class names and it works perfectly. E.g.: x<-2 y<-3 class(x

Re: [R] Re : Re: Re : Privacy rights of an old user of this list

2013-09-22 Thread Uwe Ligges
On 21.09.2013 22:40, John Gonzalez wrote: As I said previously, I'm only concerned about what was published in the archive of stat.ethz.ch. And it is OK to habe your post on Nabble (and many others) after you removed it from stat.ethz.ch? Are the swiss that bad? I visited https://stat.ethz

Re: [R] Translating recoding syntax from SPSS to R

2013-09-22 Thread Joshua Wiley
Just a slight addition to Arun's answer: within() saves typing and makes life a bit easier # set.seed(429) dat1 <- data.frame( race=sample(1:3,20,replace=TRUE), usborn=sample(0:2,20,replace=TRUE)) # within is a nice way to add variables # an