Re: [R] Smooth ecdf

2011-08-15 Thread Jorge Ivan Velez
Hi Jeff,
Take a look at ?density
HTH,
Jorge

On Mon, Aug 15, 2011 at 2:38 PM, Jeffrey Joh <> wrote:

>
>
> Is it possible to smooth an ecdf plot and get a probability density plot?
>  I have about 8000 points and I was hoping to get a density curve instead of
> a histogram.
>
>
>
> Jeff
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how can I read a xlsx file

2011-08-15 Thread Jorge Ivan Velez
Hi Albert,

Another option would be the following:

install.packages('gdata')
require(gdata)
?read.xlsx

HTH,
Jorge


On Mon, Aug 15, 2011 at 11:19 AM, albert coster <> wrote:

> Hello,
>
> How can I read a xlsx file using xlsx package?
>
> Thanks
>
> Albert
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Not sure how to use aggregate, colSums, by

2011-08-14 Thread Jorge Ivan Velez
Hi eric,

Try

lapply(with(x, split(x, e2)), function(l){
r <- with(l, aggregate(list(y, f), list(e1), sum))
colnames(r) <- c('e1', 'y', 'f')
 r
   })

HTH,
Jorge


On Sun, Aug 14, 2011 at 1:20 PM, eric <> wrote:

> I have a data frame called test shown below that i would like to summarize
> in
> a particular way :
>
> I want to show the column sums (columns y ,f) grouped by country (column
> e1). However, I'm looking for the data to be split according to column e2.
> In other words, two tables of sum by country. One table for "con" and one
> table for "std" shown in column e2. Finally at the bottom of the two
> tables,
> I would like the overall sum /Totals for all the countries for the two
> columns (y,f).  The lay outs for the two tables I'm looking for are also
> shown below in case my description isn't completely clear
>
> I would also like to be able to use the Totals of y and f for the two
> tables
> in other calculations.
>
> I can get the two sets of totals with the following commands but not the
> sums by country.
>
> colSums(test[test$e2=="std", c(3,4)])
> colSums(test[test$e2=="con", c(3,4)])
>
> I know there's an easy way to do this with a combination of colSums, by,
> aggregate but I can't seem to get it.
>
> std y   f
>
> usasum   sum
> francesum   sum
> cansum   sum
> italy   sum   sum
> Totalssum   sum
>
> con   y   f
>
> usa   sum   sum
> france   sum   sum
> can   sum   sum
> italy  sum   sum
> Totalssum   sum
>
>  e1  e2 y  f
> 1 usa std 1  1
> 2 usa std 1  2
> 3 can con 1  3
> 4  france con 1  4
> 5 can std 1  5
> 6   italy con 1  6
> 7 usa std 2  7
> 8 usa std 2  8
> 9 can con 2  9
> 10 france con 2 10
> 11can std 2 11
> 12  italy con 2 12
> 13usa std 3 13
> 14usa std 3 14
> 15can con 3 15
> 16 france con 3 16
> 17can std 3 17
> 18  italy con 3 18
> 19usa std 4 19
> 20usa std 4 20
> 21can con 4 21
> 22 france con 4 22
> 23can std 4 23
> 24  italy con 4 24
> 25usa std 5 25
> 26usa std 5 26
> 27can con 5 27
> 28 france con 5 28
> 29can std 5 29
> 30  italy con 5 30
> 31usa std 6 31
> 32usa std 6 32
> 33can con 6 33
> 34 france con 6 34
> 35can std 6 35
> 36  italy con 6 36
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Not-sure-how-to-use-aggregate-colSums-by-tp3743258p3743258.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] conditional filter resulting in 2 new dataframes

2011-08-14 Thread Jorge Ivan Velez
Hi,

Try

ifelse(initial < 5, initial, 0)
ifelse(initial >= 5, initial, 0)

and take a look at ?ifelse

HTH,
Jorge


On Sat, Aug 13, 2011 at 9:02 PM, andrewjt <> wrote:

> This is what I am starting with:
>
> initial<- matrix(c(1,5,4,8,4,4,8,6,4,2,7,5,4,5,3,2,4,6), nrow=6,
> ncol=3,dimnames=list(c("1900","1901","1902","1903","1904","1905"),
> c("sample1","sample2","sample3")))
>
> And I need to apply a filter (in this case, any value <5) to give me one
> dataframe with only the 'less than 5' values and with '0' place holders on
> the values that don't meet this criteria. The second dataframe is the same
> but for those values >=5.
>
> Should look like this:
> less <- matrix(c(1,0,4,0,4,4,0,0,4,2,0,0,4,0,3,2,4,0), nrow=6,
> ncol=3,dimnames=list(c("1900","1901","1902","1903","1904","1905"),
> c("sample1","sample2","sample3")))
> more <- matrix(c(0,5,0,8,0,0,8,6,0,0,7,5,0,5,0,0,0,6), nrow=6,
> ncol=3,dimnames=list(c("1900","1901","1902","1903","1904","1905"),
> c("sample1","sample2","sample3")))
>
> Any ideas?
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/conditional-filter-resulting-in-2-new-dataframes-tp3742232p3742232.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How do I subset a dataframe

2011-08-14 Thread Jorge Ivan Velez
Hi eric,

See

R> ?"%in%"

and try the following (untested):

subset(zeespan, !customer %in% c("ibm" , "exxon" , "sears") )

HTH,
Jorge



On Sat, Aug 13, 2011 at 7:44 PM, eric <> wrote:

> I have a dataframe zeespan. One of the columns has the name "customer". The
> data in the customer column is text. I would like to return a subset of the
> dataframe with all rows that DON'T begin with either "ibm" or "exxon", or
> "sears" in the customer column.
>
> I tried   subset(zeespan, customer != c("ibm" | "exxon" | "sears") )
>
> That didn't work and even if it did, the text would have to be an exact
> match where what I really want is "begins with".
>
> Suggestions on how to do this would be appreciated
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/How-do-I-subset-a-dataframe-tp3742172p3742172.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Correlation Matrix - p value?

2011-08-09 Thread Jorge Ivan Velez
?cor.test
cor.test(x, y, method = "spearman")$p.value

HTH,
Jorge


On Tue, Aug 9, 2011 at 8:44 AM, ScottM <> wrote:

> Hello all,
>
> I've run a Spearman's Rank test to discern relationships between landscape
> characteristics and a specific aspect of river behaviour.
>
> I've executed a correlation matrix between the one dependent variable and
> all of the predictors, which gives me a nice output of Spearman's Rho
> values.
>
> However, I also need to somehow find the "p" value, to assess the strength
> of relationship.
>
> Conducting a simple correlation between 2 variables using the:
>
> cor(var1, var2, method="spearman")
>
> command gives me an output with both the Rho and P value, but the default
> output of the matrix is simply the Rho value.  I've tried using
> summary(result), but it just produces the percentile/max/min values.
>
> Any help appreciated.
>
> Cheers,
>
> S.
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Correlation-Matrix-p-value-tp3729838p3729838.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Printing data frame with million rows

2011-08-07 Thread Jorge Ivan Velez
?write.table

HTH,
Jorge


On Sun, Aug 7, 2011 at 2:08 PM, Bansal, Vikas <> wrote:

> Dear all,
>
> I was working on number of files and at the end I got a data frame with
> approx. million rows.To prin this data frame in output, I used
>
> capture.output(print.data.frame(end,row.names=F), file = "summary", append
> = FALSE)
>
> where end is the name of my data frame and summary is the name of my output
> file.
>
> but when I checked the output there were only 1 rows and at the last it
> was written-
>
> [ reached getOption("max.print") -- omitted 923750 rows ]]
>
> Can you please tell me what is wrong with my output code? I want to print
> all million rows in my output.
>
> Thanking you,
> Warm Regards
> Vikas Bansal
> Msc Bioinformatics
> Kings College London
> __
> 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] Gamma distribution parameter estimation

2011-08-06 Thread Jorge Ivan Velez
Hi Alex,

Try

> require(MASS)
Loading required package: MASS
> b <- c(2039L, 2088L, 5966L, 2353L, 1966L, 2312L, 3305L, 2013L, 3376L,
+ 3363L, 3567L, 4798L, 2032L, 1699L, 3001L, 2329L, 3944L, 2568L,
+ 1699L, 4545L)
> fitdistr(b, 'gamma')
  shape   rate
  6.4528939045   0.0021887943
 (0.7722567310) (0.0001854559)

HTH,
Jorge


On Sat, Aug 6, 2011 at 3:14 PM, Alexander Engelhardt <> wrote:

> Hey,
> I have a set of income data which I'd like to fit to a gamma distribution.
> How can I estimate the two parameters of the gamma distribution for a
> vector, e.g.
>
> c(2039L, 2088L, 5966L, 2353L, 1966L, 2312L, 3305L, 2013L, 3376L,
> 3363L, 3567L, 4798L, 2032L, 1699L, 3001L, 2329L, 3944L, 2568L,
> 1699L, 4545L)
>
> I sense this will be a very easy one-liner, but my searching didn't come up
> with results yet.
>
> Thanks in advance,
>  Alex
>
> __**
> 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] summing columns with NAs present

2011-08-05 Thread Jorge Ivan Velez
Try

test$Sum <- rowSums(test, na.rm = TRUE)
test

HTH,
Jorge


On Fri, Aug 5, 2011 at 2:01 PM, Dimitri Liakhovitski <> wrote:

> Hello!
>
> I have a data frame with some NAs.
> test<-data.frame(a=c(1,2,NA),b=c(10,NA,20))
>
> I need to sum up values in 2 variables. However:
> test$a+test$b
> procudes NAs in rows that have NAs.
>
> How could I sum up columns while ignoring NAs (the way the function
> sum(..., na.rm=T) works?
> Thank you!
> --
> Dimitri Liakhovitski
> marketfusionanalytics.com
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] SNP Tables

2011-07-26 Thread Jorge Ivan Velez
Hi Jim,

Here is one way:

# data
x <- structure(list(category = structure(c(1L, 1L, 1L, 2L, 2L, 2L,
1L, 1L, 2L), .Label = c("case", "control"), class = "factor"),
SNP1 = c(1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L), SNP2 = c(0L,
1L, 2L, 1L, 2L, 0L, 0L, 1L, 0L), SNP3 = c(2L, 1L, 2L, 0L,
1L, 0L, 2L, 2L, 0L)), .Names = c("category", "SNP1", "SNP2",
"SNP3"), class = "data.frame", row.names = c(NA, -9L))

# transforming SNPs to factors with levels 0, 1, 2
x[, -1] <- lapply(x[, -1], function(x) factor(x, levels = 0:2))

# processing
res <- lapply(colnames(x)[-1], function(name) table(x[, 1], x[, name]))
names(res) <- colnames(x)[-1]
res

HTH,
Jorge


On Wed, Jul 27, 2011 at 12:23 AM, Jim Silverton <> wrote:

> Hello,
> I have indicators for the present of absent of a snps in columns and the
> categorey (case control column). I would like to extract ONLY the tables
> and
> the indices (SNPS) that give me 2 x 3 tables. Some gives 2x 2 tables when
> one of the allelle is missing. The data look like the matrix snpmat below:
> so the first snp should give me the following table: (aa=0, Aa=1 and AA=2)
>
> aa Aa AA
> case  23   0
> control   22   0
>
> So I should not use this one or if I am using it, then I need to see  0 0
> in
> to AA column which I don't see when I use the table command in R.
>
>
>
> snpmat
>
>
> category   SNP1 SNP2 SNP3 SNPN
> case   102 1
> case   011  2
> case   122 0
> control 0   1 01
> control 1   21 2
> control 0   00 0
> case1   02 2
> case0   121
> control  1  00 1
>
>
> --
> Thanks,
> Jim.
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Deleting rows and store the deleted rows in new data frame

2011-07-24 Thread Jorge Ivan Velez
Or just

subset(df, V5 >= 10)

See ?subset.

HTH,
Jorge


On Sun, Jul 24, 2011 at 10:01 PM, Bansal, Vikas <> wrote:

> Dear Jeff,
>
> Thanks a lot for your reply.
> I was just curious about this thing about grep that it can perform this
> kind of thing or not. Otherwise with numerical comparison I know it is very
> easy to do.Like-
>
> df <- df[df$V5 >= 10, ]
>
> Thanks a lot for your help.
>
> Thanking you,
> Warm Regards
> Vikas Bansal
> Msc Bioinformatics
> Kings College London
> 
> From: Jeff Newmiller []
> Sent: Monday, July 25, 2011 1:02 AM
> To: Bansal, Vikas; Phil Spector
> Cc: r-help@r-project.org
> Subject: Re: [R] Deleting rows and store the deleted rows in new data frame
>
> You can, but you would have to convert them to character first. It would be
> more sensible to use vector numeric comparisons. I strongly recommend that
> you go read "An Introduction to R", since you are asking questions that are
> explained there.
> ---
> Jeff Newmiller The . . Go Live...
> DCN:<> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---
> Sent from my phone. Please excuse my brevity.
>
> "Bansal, Vikas" <> wrote:
>
> Thanks for your reply.
> Can I use grep with numbers also?
>
>
>
> 5961 T 17  0  9
> 5962 T 17  0  9
> 5963 A 17  0  9
> 5964 G 13  0  10
> 5965 G 13  0  9
> 5966 G 13  0 13
> 5967 T 13  0  8
> 5968 T 13  0  5
> 5969 A 13  0 13
> 5970 G 13  0 13
> 5971 G 13  0  4
> 5972 G 13  0 13
> 5973 T 13  0 13
>
> like in 5th column.If I want only rows whose value is more than 10 in 5th
> column?
>
> Thanking you,
> Warm Regards
> Vikas Bansal
> Msc Bioinformatics
> Kings College London
> 
>
> From: Phil Spector []
> Sent: Monday, July 25, 2011 12:29 AM
> To: Bansal, Vikas
> Cc: r-help@r-project.org
> Subject: Re: [R] Deleting rows and store the deleted rows in new data frame
>
> There's no need to use sapply or loops with gre
>  p --
> it's
> already vectorized.  So you can find the rows you're
> interested in with
>
> > wh = grep('^[.,]+$',df[,9])
>
> store them with
>
> > sf = df[wh,]
>
> and delete them with
>
> > df = df[-wh,]
>- Phil Spector
> Statistical Computing Facility
> Department of Statistics
> UC Berkeley
>
>
>
> On Sun, 24 Jul 2011, Bansal, Vikas wrote:
>
> > Dear all,
> >
> > I am using grep but I did not understand the problem as I am doing
> something wrong.Please help me.
> > I am using this code-
> >
> > sf=data.frame(sapply(df[],function(x) grep('\\.&\\,', df[,9])))
> >
> > the thing is i have a data frame(df) like this-
> >>
> > 10135349467   g   G   4   0   0   5
> ,,,.,
> > 10135349468   t   T   2   0   0   5
> ,,c.,
> > 10135349469   g   G   7   0   0   5
> ,,a.,
> > 10135349470   c   C   8   0   0   5
> ,,,.,
> > 10135349471   a   A   10  0   0   5
> ,,,.,
> > 10135349472   g   G   7   0   0   6
> aa,.,,
> > 10135349473   g   G   7   0   0   6
> ,,c.,,
> > 10135349474   g   G   4   0   0   6
> ,,,.,,
> > 10135349475   a   A   8   0   0   6
> ,,,.,,
> > 10135349476   t   T   1   0   0   6
> g,,.,,
> > 10135349477   a   A   7   0   0   6
> ,,,.,,
> > 10135349478
>  a
>  A   11  0   0   6   ,,,.,,
> >
> > I want to delete those rows which contains only . and , in column 9.
> > and i want to store those rows in new data frame sf.
> >
> > so my output should be-
> >
> > df
> >
> >
> > 10135349468   t   T   2   0   0   5
> ,,c.,
> > 10135349469   g   G   7   0   0   5
> ,,a.,
> > 10135349472   g   G   7   0   0   6
> aa,.,,
> > 10135349473   g   G   7   0   0   6
> ,,c.,,
> > 10135349476   t   T   1   0   0   6
> g,,.,,
> >
> >
> > sf
> >
> > 10135349467   g   G   4   0   0   5
> ,,,.,
> > 10135349470   c   C   8   0   0   5
> ,,,.,
> > 10135349471   a   A   10
>  0
>  0   5   ,,,.,
> > 10135349474   g   G   4   0   0   6
> ,,,.,,
> > 10135349475   a   A   8   0   0   6
> ,,,.,,
> > 10135349477   a   A   7   0   0

Re: [R] Saving fExtremes estimates and k-block return level with confidence intervals.

2011-06-30 Thread Jorge Ivan Velez
Hi Peter,

Try

data.frame(n = names(res2), t(sapply(res2, function(l) l@fit$par.ests)))

for the first part.

HTH,
 Jorge


On Thu, Jun 30, 2011 at 12:16 AM, Peter Maclean <> wrote:

> I am estimating a large model by groups. How do you save the results
> and returns
> the associated quantiles?
> For this example I need a data frame
> nximubeta
> 1   0.1033614  2.5389580 0.9092611
> 2   0.3401922  0.5192882 1.5290615
> 3   0.5130798  0.5668308 1.2105666
> I also want to apply gevrlevelPlot() for each "n" or group.
>
> #Example
> n <- c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,3)
> y <- c(2,3,2,3,4,5,6,1,0,0,0,6, 2, 1, 0, 0,9,3)
> z <- as.data.frame(cbind(n,y))
> colnames(z) <- c("n","y")
> library(fExtremes)
> z <- split(z, z$n)
> res2 <-lapply(z, function(x){
>m <- as.numeric(x$y)
>gevFit(m, block = 1, type = c("pwm"))
> })
> > res2
> $`1`
> Title:
>  GEV Parameter Estimation
> Call:
>  gevFit(x = m, block = 1, type = c("pwm"))
> Estimation Type:
>   gev pwm
> Estimated Parameters:
>ximu  beta
> 0.1033614 2.5389580 0.9092611
> Description
>   Wed Jun 29 23:07:48 2011
>
> $`2`
> Title:
>  GEV Parameter Estimation
> Call:
>  gevFit(x = m, block = 1, type = c("pwm"))
> Estimation Type:
>   gev pwm
> Estimated Parameters:
>ximu  beta
> 0.3401922 0.5192882 1.5290615
> Description
>   Wed Jun 29 23:07:48 2011
>
> $`3`
> Title:
>  GEV Parameter Estimation
> Call:
>  gevFit(x = m, block = 1, type = c("pwm"))
> Estimation Type:
>   gev pwm
> Estimated Parameters:
>ximu  beta
> 0.5130798 0.5668308 1.2105666
> Description
>   Wed Jun 29 23:07:48 2011
>
>
> __
> 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] DROP OBSEVATION IN A GROUP

2011-06-30 Thread Jorge Ivan Velez
Hi Peter,

Try this:

r <- with(z, tapply(y, n, function(x) sum(x == 0) > 2))
z[!rep(r, with(z, table(n))), ]

HTH,
Jorge


On Thu, Jun 30, 2011 at 1:05 AM, Peter Maclean <> wrote:

> I tried this but did not work:
> z0<- by(z, z[,"n"], function(x) subset(x, sum(n==0)>2))
>  Peter Maclean
> Department of Economics
> UDSM
>
>
>
> - Original Message 
> From: Duncan Murdoch <>
> To: Peter Maclean <>
> Cc:
> Sent: Wed, June 29, 2011 3:33:25 PM
> Subject: Re: [R] DROP OBSEVATION IN A GROUP
>
> On 29/06/2011 4:29 PM, Peter Maclean wrote:
> > People with more experience in R I need help on this.
> > I would like to drop observation if they meet certain condition. In this
> >example
> > I would like to drop group 2 in "n" because the group in "Y" has more
> than 2
> > zeroes.
> > #Example
> > n<- c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,3)
> > y<- c(2,3,2,3,4,5,6,1,0,0,0,6, 2, 1, 0, 0,9,3)
> > z<- as.data.frame(cbind(n,y))
> > colnames(z)<- c("n","y")
> z0<- by(z, z[,"n"], function(x) subset(x, sum(n==0)>2))
>
>
> The general way to drop observations is to construct a logical vector to
> use as
> an index.  Entries which are FALSE are dropped.
>
> Doing that based on your "more than 2 zeroes" rule looks a little tricky; I
> think you want to count zeros first (e.g. using by()), then construct the
> TRUE/FALSE vector based on that.
>
> 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.
>
> __
> 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] 2d rndom walk

2011-06-29 Thread Jorge Ivan Velez
Hi Komal,
Try this:

walk2d<-function(n){
rw <- matrix(0, ncol = 2, nrow = n)

# generate the indices to set the deltas
indx <- cbind(seq(n), sample(c(1, 2), n, TRUE))

# now set the values
rw[indx] <- sample(c(-1, 1), n, TRUE)

# cumsum the columns
rw[,1] <- cumsum(rw[, 1])
rw[,2] <- cumsum(rw[, 2])
cbind(rw[,1],rw[,2])  # changed this

}

# example
n <- 100
rw <- walk2d(n)
plot(rw, xlab="x", ylab="y", main="Random Walk Simulation In Two
Dimensions",
 xlim = range(rw[,1]), ylim = range(rw[,2]), las = 1)

HTH,
Jorge


On Wed, Jun 29, 2011 at 11:44 AM, Komal <> wrote:

>
>
>
> walk.2d<-function(n)
> {
> rw <- matrix(0, ncol = 2, nrow = n)
>
> # generate the indices to set the deltas
> indx <- cbind(seq(n), sample(c(1, 2), n, TRUE))
>
> # now set the values
> rw[indx] <- sample(c(-1, 1), n, TRUE)
>
> # cumsum the columns
> rw[,1] <- cumsum(rw[, 1])
> rw[,2] <- cumsum(rw[, 2])
>
> return(rw[,1],rw[,2])
>
> }
> n<-1000
>
> plot(walk.2d(n), type="n",xlab="x",ylab="y",main="Random Walk Simulation In
> Two Dimensions",xlim=range(rw[,1]),ylim=range(rw[,2]))
>
># use 'segments' to color each path
> segments(head(rw[, 1], -1), head(rw[, 2], -1), tail(rw[, 1], -1), tail(rw[,
> 2], -1), col ="blue")
>
>
> This code is giving me error in the return()... what to write in
> return()???
> please help.
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/2d-rndom-walk-tp3632468p3633249.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simple simulations

2011-06-27 Thread Jorge Ivan Velez
Hi robcinm,

You might also consider:

# data
x <- c(rep(0, 20), 1:37)

# number of simulations
B <- 1000

# result:  TRUE/FALSE
out <- replicate(B, {
  y <- sample(x, 3, replace = FALSE)
  all(y == 0)
  })
mean(out)

HTH,
Jorge


On Mon, Jun 27, 2011 at 5:08 PM, robcinm <> wrote:

> I am taking a basic statistics course this summer, and while the majority
> of
> the class is using a statistical package that came with the book, I am
> doing
> everything in R for practical reasons. Forgive me if there is
> documentation/instruction easily available on this topic, but Google and
> forums searches left me with nothing.
>
> We are learning about randomness at the moment and are required to create
> simulations to use as an example. For the problem in the text, there are 57
> numbers with 1 through 20 belonging to the same “group”, meaning the
> probability that a number in that group is picked is 20/57, and 21 through
> 57 are individuals, belonging to no larger group. The point of the exercise
> is to simulate the probability of 1 through 20 being chosen at random (with
> no replacement) three times in a row through hundreds of trials. This is
> the
> basic syntax I have been using…
>
> sample(c(rep(0, 20), seq(1:37)), 3, replace = F)
>
> That works just fine, but I am wondering if there is a more efficient way
> of
> doing this. Right now, I am hitting the up arrow and hitting “enter”
> hundreds of times and making note of each time a trial results in 0,0,0. If
> I place this syntax in a rep function, it just repeats the same output of a
> single sample x times instead of giving me new data.
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Simple-simulations-tp3628863p3628863.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Fw:

2011-06-26 Thread Jorge Ivan Velez
Hi Ungku,

Check

?persp
?volcano

in the R console.

HTH,
Jorge


On Sun, Jun 26, 2011 at 9:22 PM, Ungku Akashah <> wrote:

>
>
>
> - Forwarded Message -
> From: Ungku Akashah <>
> To: "r-help@r-project.org" <>
> Sent: Friday, June 24, 2011 3:15 PM
> Subject:
>
>
> hello.
> I need some help about this R software. I've been searching for volcano
> plot script for long, but still not found.
> May i request the script for volcano plot. If able, pls include any tips
> about volcano plot.
>
>
> thank you.
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] i want to unsubscribe

2011-06-25 Thread Jorge Ivan Velez
Check "R-help Subscribers" at https://stat.ethz.ch/mailman/listinfo/r-help

HTH,
Jorge


On Sun, Jun 26, 2011 at 2:17 AM, elisheva corn <> wrote:

> how do i unsubscribe
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ddply to count frequency of combinations

2011-06-21 Thread Jorge Ivan Velez
Hi Idris,

I do not know what the correct use of ddply would be, but here is another
option using paste() and table();

data.frame(with(df, table(paste("(", x, ",", y, ")", sep = ""

HTH,
Jorge


On Tue, Jun 21, 2011 at 2:30 PM, Idris Raja <> wrote:

> I have a dataframe df with two columns x and y. I want to count the number
> of times a unique x, y combination occurs.
>
> For example
>
> x<- c(1,2,3,4,5,1,2,3,4)
> y<- c(1,2,3,4,5,1,2,4,1)
>
> df<-as.data.frame(cbind(x, y))
>
> #what is the correct way to use ddply for this example?
> ddply(df, c('x','y', summarize, ??)
>
> #desired output -- format and order doesn't matter
> # (x, y) count
> #
> # (1, 1) 2
> # (2, 2) 2
> # (3, 3) 1
> # (4, 4) 1
> # (5, 5) 1
> # (2, 3) 1
> # (3, 4) 1
> # (4, 1) 1
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] omitting columns from a data frame

2011-06-20 Thread Jorge Ivan Velez
Hi Erin,

One option woild be subset(), especially the "select" parameter.

HTH,
Jorge


On Mon, Jun 20, 2011 at 11:45 PM, Erin Hodgess <> wrote:

> Dear R People:
>
> I have a data frame, xm1, which has 12 rows and 4 columns.
>
> If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as
> it should be.
>
> Now, is there a way to use the names of the columns to omit them, please?
>
> Thanks so much in advance!
>
> Sincerely,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodg...@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.
>

[[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] Linear model - coefficients

2011-06-12 Thread Jorge Ivan Velez
Hi Robert,

Try this:

reg2 <- lm( Y ~ factor(x1) + factor(x2) + factor(x3) + factor(x4) +
factor(x5) - 1, data = X  )
cof(ref2)

HTH,
Jorge


On Sun, Jun 12, 2011 at 4:40 PM, Robert Ruser <> wrote:

> Prof. Ripley, thank you very much for the answer but wanted to get
> something else. There is an example and an explanation:
>
> options(contrasts=c("contr.sum","contr.poly")) # contr.sum uses ‘sum
> to zero contrasts’
> Y <- c(6,3,5,2,3,1,1,6,6,6,7,4,1,6,6,6,6,1)
> X <- structure(list(x1 = c(2L, 3L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 2L,
> 3L, 2L, 1L, 1L, 2L, 1L, 2L, 3L), x2 = c(3L, 3L, 2L, 3L, 1L, 3L,
> 2L, 3L, 2L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 1L, 1L), x3 = c(1L, 1L,
> 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L
> ), x4 = c(1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 2L, 2L, 1L, 2L), x5 = c(1L, 1L, 2L, 2L, 3L, 3L, 3L, 2L, 2L,
> 2L, 1L, 3L, 3L, 1L, 1L, 1L, 2L, 3L)), .Names = c("x1", "x2",
> "x3", "x4", "x5"), row.names = c(NA, 18L), class = "data.frame")
>
> reg <- lm( Y ~ factor(X$x1) + factor(X$x2) + factor(X$x3) +
> factor(X$x4) + factor(X$x5)   )
> coef(reg)
>
> and e.g. I get two coefficients for variable x1 (3-levels variable)
> but I would like to get the third. Of course I can calculate a3=
> -(a1+a2) where a1 and a2 are coefficients of the variable x1.
>
> I hope that I manage to explain my problem.
>
> Robert
>
> 2011/6/12 Prof Brian Ripley <>:
> > ?dummy.coef
> >
> > (NB: 'R' does as you tell it, and if you ask for the default contrasts
> you
> > get coefficients a2 and a3, not a1 and a2.  So perhaps you did something
> > else and failed to tell us?  And see the comment in ?dummy.coef about
> > treatment contrasts.)
> >
> >
> > On Sun, 12 Jun 2011, Robert Ruser wrote:
> >
> >> Dear R Users,
> >> Using lm() function with categorical variable R use contrasts. Let
> >> assume that I have one X independent variable with 3-levels. Because R
> >> estimate only 2 parameters ( e.g. a1, a2)  the coef function returns
> >> only 2 estimators. Is there any function or trick to get another a3
> >> values. I know that using contrast sum (?contr.sum) I could compute a3
> >> = -(a1+a2). But I have many independent categorical variables and I'm
> >> looking for a fast solution.
> >>
> >> Robert
> >>
> >> __
> >> 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, UKFax:  +44 1865 272595
> >
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Likelihood ratio test

2011-06-12 Thread Jorge Ivan Velez
Hi Diviya,

Take a look at the lrtest function in the lmtest package:

install.packages('lmtest)
require(lmtest)
?lrtest

HTH,
Jorge


On Sun, Jun 12, 2011 at 1:16 PM, Diviya Smith <> wrote:

> Hello there,
>
> I want to perform a likelihood ratio test to check if a single exponential
> or a sum of 2 exponentials provides the best fit to my data. I am new to R
> programming and I am not sure if there is a direct function for doing this
> and whats the best way to go about it?
>
> #data
> x <- c(1 ,10,  20,  30,  40,  50,  60,  70,  80,  90, 100)
> y <- c(0.033823,  0.014779,  0.004698,  0.001584, -0.002017, -0.003436,
> -0.06, -0.004626, -0.004626, -0.004626, -0.004626)
>
> data <- data.frame(x,y)
>
> Specifically, I would like to test if the model1 or model2 provides the
> best
> fit to the data-
> model 1: y = a*exp(-m*x) + c
> model 2: y = a*exp(-(m1+m2)*x) + c
>
> Likelihood ratio test = L(data| model1)/ L(data | model2)
>
> Any help would be most appreciated. Thanks in advance.
>
> Diviya
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Counting the Number of Letters in a row

2011-06-10 Thread Jorge Ivan Velez
Hi Abraham,

Try

foo <- function(x){
x <- as.character(x)
 sapply(strsplit(x, " "), function(s) sum(nchar(s)))
}
foo(f1$keyword)

HTH,
Jorge


On Fri, Jun 10, 2011 at 12:48 PM, Abraham Mathew <> wrote:

> I'm trying to find the total number of letters in a row of a data frame.
>
> Let's say I have the following data frame.
>
> f1 <- data.frame(keyword=c("I live in Denver", I live in Kansas City, MO",
> "Pizza is good"))
>
> The following function gives me the number of characters in each string.
> So for "I live in Denver", I get 1, 4, 2, and 6. However, I want to know
> the
> total
> number of characters (13).
>
> sapply(strsplit(as.character(f1$keyword), " "), nchar)
>
>
> Thanks,
> Abraham
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to subset based on column name that is a number ?

2011-06-09 Thread Jorge Ivan Velez
Hi Mauricio,

Try the following:

# using the iris data
require(MASS)
x <- iris
x[x[, 5] == 'setosa',]

# and your data
dframe[dframe[, 1] == "FY11_Q4", ]

HTH,
Jorge


On Thu, Jun 9, 2011 at 3:34 PM, Mauricio Cornejo <> wrote:

> Hi,
>
> I have a data frame with column names "1", "2", "3", ... and I'd like to
> extract
> a subset based on the values in the first column.  None of the methods I
> tried
> worked (below).
>
>
> x <- subset(dframe, 1 = = "My Text")
> x <- subset(dframe, "1" = = "My Text")
> x <- subset(dframe, names(dframe)[1] = = "My Text")
> Q <- dframe[1 = = "FY11_Q4",]
> Q <- dframe['1'=="FY11_Q4",]
> Q <- dframe[names(dframe)[1]=="FY11_Q4",]
>
>
> Might anyone have a suggestion?
>
> Many thanks,
> Mauricio
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem in R documentation

2011-06-06 Thread Jorge Ivan Velez
Hi Siddharth,

adf.test() is part of the "tseries" package, so you need to download and
install it before using that function. Try the following and let us now what
you get:

install.packages('tseries')
require(tseries)
?adf.test

HTH,
Jorge


On Mon, Jun 6, 2011 at 2:41 AM, siddharth arun <> wrote:

> I am not able to run Dickey-Fuller test.
> adf.test() function is not working. It is showing 'Error: could not find
> function "adf.test"
>
>
> Can any tell how to call "time series" library?
>
> --
> Siddharth Arun,
> 4th Year Undergraduate student
> Industrial Engineering and Management,
> IIT Kharagpur
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to convert a factor column into a numeric one?

2011-06-04 Thread Jorge Ivan Velez
Dr. LaBudde,

Perhaps

as.numeric(as.character(x))

is what you are looking for.

HTH,
Jorge


On Sun, Jun 5, 2011 at 12:31 AM, Robert A. LaBudde <> wrote:

> I have a data frame:
>
> > head(df)
>  Time Temp Conc ReplLog10
> 10  -20H1 6.406547
> 22  -20H1 5.738683
> 37  -20H1 5.796394
> 4   14  -20H1 4.413691
> 504H1 6.406547
> 774H1 5.705433
> > str(df)
> 'data.frame':   177 obs. of  5 variables:
>  $ Time : Factor w/ 4 levels "0","2","7","14": 1 2 3 4 1 3 4 1 3 4 ...
>  $ Temp : Factor w/ 4 levels "-20","4","25",..: 1 1 1 1 2 2 2 3 3 3 ...
>  $ Conc : Factor w/ 3 levels "H","L","M": 1 1 1 1 1 1 1 1 1 1 ...
>  $ Repl : Factor w/ 5 levels "1","2","3","4",..: 1 1 1 1 1 1 1 1 1 1 ...
>  $ Log10: num  6.41 5.74 5.8 4.41 6.41 ...
> > levels(df$Temp)
> [1] "-20" "4"   "25"  "45"
> > levels(df$Time)
> [1] "0"  "2"  "7"  "14"
>
> As you can see, "Time" and "Temp" are currently factors, not numeric.
>
> I would like to change these columns into numerical ones.
>
> df$Time<- as.numeric(df$Time)
>
> doesn't work, as it changes to the factor level indices (1,2,3,4) instead
> of the values (0,2,7,14).
>
> There must be a direct way of doing this in R.
>
> I tried recode() in 'car':
>
> > df$Temp<- recode(df$Temp, '1=-20;2=25;3=4;4=45',as.factor.result=FALSE)
> > head(df)
>  Time Temp Conc Repl Freq
> 10  -20H1 6.406547
> 22  -20H1 5.738683
> 37  -20H1 5.796394
> 4   14  -20H1 4.413691
> 50   45H1 6.406547
> 77   45H1 5.705433
>
> but note that the values for 'Temp' in rows 5 and 7 are 45 and not 4, as
> expected, although the result is numeric. The same happens if I use the
> order given by levels(df$Temp) instead of the sort order in the recode() 2nd
> argument.
>
> Any hints?
> 
> Robert A. LaBudde, PhD, PAS, Dpl. ACAFS  e-mail: r...@lcfltd.com
> Least Cost Formulations, Ltd.URL: http://lcfltd.com/
> 824 Timberlake Drive Tel: 757-467-0954
> Virginia Beach, VA 23464-3239Fax: 757-467-2947
>
> "Vere scire est per causas scire"
>
> __
> 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] Transforming a data matrix into a vector

2011-05-30 Thread Jorge Ivan Velez
Hi Charles,

Try

rep(c(tmp), each = 3)

HTH,
Jorge


On Mon, May 30, 2011 at 4:22 PM, Charles Ellis <> wrote:

> Hi,
>
> I am trying to transform a data matrix into a vector and have not be able
> to accomplish want I am looking for.  The setup is as follows. I start with
> a 3 x 3 matrix:
>
> 5 1 3
> 3 3 2
> 1 2 4
>
> I would like to transorm it into a 27 x 1 vector of the follwing form
>
> 5
> 5
> 5
> 1
> 1
> 1
> 3
> 3
> 3
> .
> .
> .
> 1
> 1
> 1
> 2
> 2
> 2
> 4
> 4
> 4
>
> In essense I want to create a vector in which each element of the original
> matrix is repeated three times, starting with cell [1,1] and ending with
> cell [3,3].
> This is small example of the larger problem I am trying to solve.  The
> actual data matrix is 352 x 15, and I would like to end up with a 26,400 x 1
> vector.  So each element of the data matrix is repeated 5 times.
>
> Any suggestions or hints would be much appreciated.  Thanks!
>
> I am using;
> R version 2.12.2 (2011-02-25)
> Copyright (C) 2011 The R Foundation for Statistical Computing
> ISBN 3-900051-07-0
> Platform: i386-pc-mingw32/i386 (32-bit)
>
> Cheers,
> Charles
>
> __
> 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] Simulation from discrete uniform

2011-05-29 Thread Jorge Ivan Velez
Hi Serdar,

Take a look at the following:

> sample(0:9, 100, replace = FALSE)
Error in sample(0:9, 100, replace = FALSE) :
  cannot take a sample larger than the population when 'replace = FALSE'
> sample(0:9, 100, replace = TRUE)
  [1] 5 6 5 7 3 0 8 4 8 2 2 4 7 6 0 7 0 0 0 7 5 6 3 6 0 9 6 1 2 6 9 0 0 4 7
9 8 6 4 7 0
 [42] 4 6 1 8 2 5 6 3 6 5 1 7 6 0 9 5 5 3 6 3 8 7 5 1 2 3 6 6 9 3 6 5 6 2 5
9 3 6 5 0 7
 [83] 8 0 8 7 3 9 9 1 4 4 1 1 0 9 8 1 9 3

HTH,
Jorge


On Sun, May 29, 2011 at 6:38 PM, SERDAR NESLIHANOGLU <> wrote:

> Hi
>
> Also , same problem to create discrete uniform Distribution ,
>
> But  sample () and  runif()  not useful to generate  discrete uniform .
>
> Ex:
>
>
> > u<-round(runif(10*10,min=1,max=10),0)
>
> > table(u)
>
> u
>
>  1 2 3 4 5 6 7 8 9 10
>
>  6 10  9 10 14  6 11 14 12  8
>
>
>
> Not useful for large number
>
>
> OR
>
> # for generate large number
>
>
> dus <- sample(0:9, 100, replace = FALSE)
>
> Error in base::sample(x, size, replace = replace, prob = prob, ...) :
>
>  cannot take a sample larger than the population when 'replace = FALSE'
>
>
>  DO you have any suggestion my question ?
>
>
> Need to generate 1000*10 number from 1:250 with discrete uniform
> distribution ?
>
>
> Regards,
>
> Serdar
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to compute the inverse percentile of a given observation w.r.t. a reference distribution

2011-05-25 Thread Jorge Ivan Velez
Hi Rudi,

Take a look at ?ecdf

HTH,
Jorge


On Wed, May 25, 2011 at 3:42 PM, rudi <> wrote:

> Hi,
>
> can anyone help me to figure out how to compute the percentile of an
> individual observation with respect to a reference distribution.
>
> What I mean is. Let's assume I have a vector consisting of 10 numbers
> {3,5,8,1,9,5,4,3,5.5,7} and I want figure out what percentile the
> number 4.9 corresponds to. I failed to find any reference to such a
> function, although I would assume this must frequently be necessary.
>
> Thanks in advance for you help.
>
> /Rudi
>
> __
> 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] convert binary vector to time series of sum(x)/minute

2011-05-21 Thread Jorge Ivan Velez
Hi mac,

Try

N <- 6000
x <- sample(1:0, N, TRUE)
tapply(x, rep(1:(N/60), each = 60), sum)

HTH,
Jorge


On Sat, May 21, 2011 at 1:59 PM, andyjmac <> wrote:

> Dear members,
>
> I apologize for the relatively simple request, but I couldn't find exactly
> what I was looking for. I have a binary vector [1,0] representing
> presence/absence at 1 second intervals over length(N). I would like to
> convert this to a new time series vector with N/60 elements that represent
> the sum of x/minute.
>
> In other words, I'd like to get from:
>
> e.g. x = [1,0,1,1,0,1,1,1,0,0,0,1,0,1, ... ] *N=6,000
>
> to
>
> e.g. x = [35, 40, 10, 29, ... ] *where each element has min=0 and max=60
> over length N=100
>
> Thanks so much,
>
> mac
> Kyoto University, Japan
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/convert-binary-vector-to-time-series-of-sum-x-minute-tp3540942p3540942.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Adding a numeric to all values in the dataframe

2011-05-19 Thread Jorge Ivan Velez
Hi,

Does the following work for you?

set.seed(123)
d <- data.frame(x = rpois(10, 4), y = rnorm(10))
d
d + 2

See ?within for one more option.

HTH,
Jorge


On Thu, May 19, 2011 at 11:54 PM, Ramya <> wrote:

> Hi there
>
> I just want to add 2 to all the values in dataframe.
>
> I tried using sapply but it seem to die all the time.
>
> Any help would be appreciated.
>
> Thanks
> Ramya
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Adding-a-numeric-to-all-values-in-the-dataframe-tp3537594p3537594.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Separating boot results

2011-05-19 Thread Jorge Ivan Velez
Hmmm...  I am sorry Patrick, it should have been

*
 a <- codboot[c(4)]
round(a$bca[4:5], 2)   # note I replaced "," by ":"

Best,
Jorge

*



>
> On Thu, May 19, 2011 at 3:08 PM, Patrick Santoso <> wrote:
>
>>  Thanks for the suggestion Jorge!
>>
>>  - that gives me subscript out of bounds error. perhaps I can tweak the
>> parameters? I've never worked with that command.
>>
>> Pat
>>
>>  On Thu, May 19, 2011 at 2:12 PM, Jorge Ivan Velez <> wrote:
>>
>>> Hi Patrick,
>>>
>>> How about this (untested)?
>>>
>>> a <- codboot[c(4)]
>>> round(a$bca[4, 5], 2)
>>>
>>> HTH,
>>> Jorge
>>>
>>>
>>> On Thu, May 19, 2011 at 7:20 AM, Patrick Santoso <> wrote:
>>>
>>>> Good Morning,
>>>>
>>>> I'm having what I hope to be a simple problem. I am generating bootstrap
>>>> confidence intervals using package (boot) - which works perfectly. The
>>>> issue
>>>> I am having is getting the results into a format which I can write out
>>>> to a
>>>> database. To be clear I am having no problems generating the results, I
>>>> just
>>>> need to convert the format of the results such that I can store the
>>>> results
>>>> in a dataframe to save out to a database.
>>>>
>>>> I am doing the following:
>>>>
>>>> ## Generate 20,000 bootstrap samples
>>>> cod.boot <- boot(trimmed$ratio, cod, R=2)
>>>>
>>>> ## generate 90% BCA boostrap confidence intervals
>>>> codboot <- boot.ci(cod.boot,conf = c(0.90), type= c("bca"))
>>>>
>>>> At this point I have stored the answer I want to the variable codboot,
>>>> but
>>>> the problem is it is in the format as follows:
>>>>
>>>> BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
>>>> Based on 2 bootstrap replicates
>>>>
>>>> CALL :
>>>> boot.ci(boot.out = cod.boot, conf = c(0.9), type = c("bca"))
>>>>
>>>> Intervals :
>>>> Level   BCa
>>>> 90%   ( 6.10, 10.23 )
>>>> Calculations and Intervals on Original Scale
>>>>
>>>> What I would like is the 6.10, and 10.23 each stored in their own
>>>> variables
>>>> so I can combine them into my existing dataframe (using cbind). The best
>>>> I've been able to do so far is:
>>>>
>>>> a <- codboot[c(4)]
>>>>
>>>> which gives me a:
>>>>
>>>> $bca
>>>> conf
>>>> [1,]  0.9 2343.41 19683.87 6.099788 10.23007
>>>>
>>>> which is closer, but I cannot parse this variable enough to get the 6.10
>>>> and
>>>> 10.23 out since apparently strsplit doesn't allow splitting on spaces.
>>>>
>>>> Any help would be greatly appreciated!
>>>>
>>>> Best Regards & Thank You in Advance
>>>>
>>>> Patrick
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>>
>>>> Patrick Santoso
>>>>
>>>> University of New Hampshire
>>>>
>>>>[[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.
>>>>
>>>
>>>
>>
>>
>> --
>>
>> Patrick Santoso
>>
>> 603 969 4673
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to get rid of the index in result file

2011-05-19 Thread Jorge Ivan Velez
Hi Yighua,

Try

> m <- 2.35343
> m
[1] 2.35343
> cat(m)
2.35343

HTH,
Jorge


On Thu, May 19, 2011 at 2:35 PM, Hu, Yinghua <> wrote:

> Hi,
>
> I am running some function in Ubuntu command line and get some problem. I
> used some command like below
>
> $ R --slave -vanilla < my_infile > my_outfile
>
> The return should be one number in the my_outfile. In the my_infile, I call
> one extra function and it has code like "return x".
>
> However, in the output file my_outfile
>
> It shows
>
> [1] 2.35343
>
> How do I get only
>
> 2.35343
>
> I mean to get rid of "[1]" part. Thanks a lot!
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Separating boot results

2011-05-19 Thread Jorge Ivan Velez
Hi Patrick,

How about this (untested)?

a <- codboot[c(4)]
round(a$bca[4, 5], 2)

HTH,
Jorge


On Thu, May 19, 2011 at 7:20 AM, Patrick Santoso <> wrote:

> Good Morning,
>
> I'm having what I hope to be a simple problem. I am generating bootstrap
> confidence intervals using package (boot) - which works perfectly. The
> issue
> I am having is getting the results into a format which I can write out to a
> database. To be clear I am having no problems generating the results, I
> just
> need to convert the format of the results such that I can store the results
> in a dataframe to save out to a database.
>
> I am doing the following:
>
> ## Generate 20,000 bootstrap samples
> cod.boot <- boot(trimmed$ratio, cod, R=2)
>
> ## generate 90% BCA boostrap confidence intervals
> codboot <- boot.ci(cod.boot,conf = c(0.90), type= c("bca"))
>
> At this point I have stored the answer I want to the variable codboot, but
> the problem is it is in the format as follows:
>
> BOOTSTRAP CONFIDENCE INTERVAL CALCULATIONS
> Based on 2 bootstrap replicates
>
> CALL :
> boot.ci(boot.out = cod.boot, conf = c(0.9), type = c("bca"))
>
> Intervals :
> Level   BCa
> 90%   ( 6.10, 10.23 )
> Calculations and Intervals on Original Scale
>
> What I would like is the 6.10, and 10.23 each stored in their own variables
> so I can combine them into my existing dataframe (using cbind). The best
> I've been able to do so far is:
>
> a <- codboot[c(4)]
>
> which gives me a:
>
> $bca
> conf
> [1,]  0.9 2343.41 19683.87 6.099788 10.23007
>
> which is closer, but I cannot parse this variable enough to get the 6.10
> and
> 10.23 out since apparently strsplit doesn't allow splitting on spaces.
>
> Any help would be greatly appreciated!
>
> Best Regards & Thank You in Advance
>
> Patrick
>
>
>
>
>
> --
>
> Patrick Santoso
>
> University of New Hampshire
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Finding row in matrix with minimum column

2011-05-18 Thread Jorge Ivan Velez
Hi Worik,

See ?which.min

x <- matrix(c(7, 7, 9, 7, 7, 9, 2, 9), ncol = 2, byrow = FALSE)
which.min(x[,2])
x[which.min(x[,2]), ]


HTH,
Jorge

On Wed, May 18, 2011 at 10:38 PM, Worik R <> wrote:

> Friends
>
> If I have a matrix such as...
>
> [,1] [,2]
> [1,]77
> [2,]79
> [3,]9   2
> [4,]79
>
> And I want to find the row number that has the minimum value of column 2
> (row 3 in this  case) how can I do it?  Is there a simple way?
>
> cheers
> Worik
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] subsetting a list of dataframes

2011-05-17 Thread Jorge Ivan Velez
Hi Lara,

You might try the following (untested):

yourlistofdataframes[sapply(yourlistofdataframes, function(d) nrow(d) > 1)]

HTH,
Jorge


On Tue, May 17, 2011 at 4:24 PM, Lara Poplarski <> wrote:

> Hello All,
>
> I have a list of dataframes, and I need to subset it by keeping only those
> dataframes in the list that meet a certain criterion. Specifically, I need
> to generate a second list which only includes those dataframes whose number
> of rows is > 1.
>
> Could someone suggest how to do this? I have come close to what I need with
> loops and such, but there must be a less clumsy way...
>
> Many thanks,
> Lara
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Simulating correlations with varying sample sizes

2011-05-16 Thread Jorge Ivan Velez
Hi Holger,

Replace "N" by "N[i]".

HTH,
Jorge


On Mon, May 16, 2011 at 9:42 AM, Holger Steinmetz <> wrote:

> Hi there,
>
> I would like to draw 10 correlations from a bivariate population - but
> every
> draw should be done with a different sample size. I thought I could to this
> with a loop:
>
> r=numeric(10) #Goal vector
> N = c(1000,100,80,250,125,375,90,211,160,540) #Sample size vector
> for(i in 1:10) {
>data <- mvrnorm(n=N,mu=c(0,0),Sigma=matrix(c(1,.3,.3,1),2))
>r[i] <- cor(data[,1],data[,2])
>}
>
> Goal: The 10 correlations shall be contained in the r-vector.
> However, this does not work. I get an error that "arguments do not match"
>
> Has anybody an idea?
>
> Best,
> Holger
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Simulating-correlations-with-varying-sample-sizes-tp3526231p3526231.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Quick question: Omitting rows and cols with certain percents of missing values

2011-05-13 Thread Jorge Ivan Velez
Hi Vickie,

You might try the following:

# some data
set.seed(123)
X <- matrix(rnorm(1000), ncol = 20)
X[sample(1000, 100)] <- NA

# excluding rows with NA >20%
X[!rowMeans(is.na(X)) > 0.2, ]

# excluding columns with NA >10%
X[, !colMeans(is.na(X)) > 0.1]

See ?is.na, ?rowMeans and ?colMeans for more information.

HTH,
Jorge

On Fri, May 13, 2011 at 9:42 AM, Vickie S <> wrote:

>
> Hi
> naive question.
> It is possible to get R command for omitting rows or cols with missing
> values present.
>
> But
> if i want to omit rows or cols with i.e . >20% missing values, I
> could´t find any package-based command, probably because it is too
> simple for anyone to do that manually, though not for me. Can anyone
> please help me ?
>
> - vickie
>
>
>
>
>
>
>
>
>
>
>
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Generating a best fit line for non linear data

2011-04-28 Thread Jorge Ivan Velez
Hi,

Try

> d <- data.frame(samples, species)
> fit = nls(species ~ a *(1 - exp(-b*samples)), start = list(a = 27, b =
.15), data = d)
> summary(fit)

Formula: species ~ a * (1 - exp(-b * samples))

Parameters:
  Estimate Std. Error t value Pr(>|t|)
a 35.824723.02073  11.860 6.10e-10 ***
b  0.071680.01023   7.009 1.53e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.333 on 18 degrees of freedom

Number of iterations to convergence: 5
Achieved convergence tolerance: 2.837e-06

HTH
Jorge


On Thu, Apr 28, 2011 at 4:56 PM, BornSurvivor <> wrote:

> I have the following data set, and I have to find the line of best fit
> using
> this equation,
> y = a*(1 - exp(-b*x)).
>
> samples = seq(1,20,by=1)
> species = c(5,8,9,9,11,11,12,15,17,19,20,20,21,23,23,25,25,27,27,27)
> plot(samples,species, main = "Accumulation Curve for Tree Species
> Richness",
> xlab = "Samples", ylab = "Number of Species")
> curve((y = 27*(1 - exp(-.15*x))),from=0,to=20,add = T)
>
> I tried to find the best fit curve using:
>
> fit = nls(species ~ a *(1 - exp(-b*x)),start = list(a = 27, b = .15)
>
> but I get a "parameters without starting value in 'data': x" and I don't
> have any idea what this means, or how to fix the above code.
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Generating-a-best-fit-line-for-non-linear-data-tp3482193p3482193.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] MASS fitdistr with plyr or data.table?

2011-04-27 Thread Jorge Ivan Velez
Hi Justin,

One way of doing it is using a combination of tapply() and sapply() as
follows:

# data
set.seed(144)
weib.dist<-rweibull(1,shape=3,scale=8)
weib.test.too<-data.frame(cbind(1:10,weib.dist))
names(weib.test.too)<-c('site','wind_speed')

# results
require(MASS)
out <- with(weib.test.too, tapply(wind_speed, site, function(x) fitdistr(x,
'weibull')))
estimates <- t(sapply(out, "[[", 1))
SDs <- t(sapply(out, "[[", 2))
estimates
SDs

HTH,
Jorge


On Wed, Apr 27, 2011 at 4:55 PM, Justin Haynes <> wrote:

> I am trying to extract the shape and scale parameters of a wind speed
> distribution for different sites.  I can do this in a clunky way, but
> I was hoping to find a way using data.table or plyr.  However, when I
> try I am met with the following:
>
> set.seed(144)
> weib.dist<-rweibull(1,shape=3,scale=8)
> weib.test<-data.table(cbind(1:10,weib.dist))
> names(weib.test)<-c('site','wind_speed')
>
> fitted<-weib.test[,fitdistr(wind_speed,'weibull'),by=site]
>
> Error in class(ans[[length(byval) + jj]]) = class(testj[[jj]]) :
>  invalid to set the class to matrix unless the dimension attribute is
> of length 2 (was 0)
> In addition: Warning messages:
> 1: In dweibull(x, shape, scale, log) : NaNs produced
> ...
> 10: In dweibull(x, shape, scale, log) : NaNs produced
>
> (the warning messages are normal from what I can tell)
>
> or using plyr:
>
> set.seed(144)
> weib.dist<-rweibull(1,shape=3,scale=8)
> weib.test.too<-data.frame(cbind(1:10,weib.dist))
> names(weib.test.too)<-c('site','wind_speed')
>
> fitted<-ddply(weib.test.too,.(site),fitdistr,'weibull')
>
> Error in .fun(piece, ...) : 'x' must be a non-empty numeric vector
>
> those sound like similar errors to me, but I can't figure out how to
> make them go away!
>
> to prove I'm not crazy:
>
> fitdistr(weib.dist,'weibull')$estimate
>   shapescale
> 2.996815 8.009757
> Warning messages:
> 1: In dweibull(x, shape, scale, log) : NaNs produced
> 2: In dweibull(x, shape, scale, log) : NaNs produced
> 3: In dweibull(x, shape, scale, log) : NaNs produced
> 4: In dweibull(x, shape, scale, log) : NaNs produced
>
> Thanks
>
> Justin
>
> __
> 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] Question on list object

2011-04-27 Thread Jorge Ivan Velez
Hi Christofer,

You might try

sapply(listObj, function(l) l[1:max(sapply(listObj, length))] )

HTH,
Jorge


On Wed, Apr 27, 2011 at 1:23 PM, Bogaso Christofer <> wrote:

> Dear all, let say, I have following list object:
>
>
>
> listObj <- vector("list", length = 3)
>
> listObj[[1]] <- rnorm(3)
>
> listObj[[2]] <- rnorm(4)
>
> listObj[[3]] <- rnorm(5)
>
>
>
> Now I want to convert above list into a Matrix. Ofcourse I can do it using
> "Reduce("rbind", listObj)". However as you notice that as elements of that
> list are arbitrary length vectors, I cant use this trick. What I want is to
> have a matrix with 3x5 dimension, where the remaining element of each row
> with be filled with NA, i.e I want :
>
>
>
> rbind(c(listObj[[1]], c(NA, NA)), c(listObj[[2]], c(NA)),listObj[[3]])
>
>
>
> Is there any better way on how I can do that more directly?
>
>
>
> Thanks and regards,
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Normality tests

2011-04-26 Thread Jorge Ivan Velez
Hi Bruce,

One way is via apply()

# some data
set.seed(123)
X <- matrix(rnorm(100), ncol = 5)
X

# tests
t(apply(X, 2, function(x){
sw <- shapiro.test(x)
c(sw$statistic, P = sw$p.value)
}))

See ?apply and ?str and ?shapiro.test for more information.

HTH,
Jorge


On Tue, Apr 26, 2011 at 4:15 PM, Bruce Kindseth <> wrote:

> I have a large amount of data which I break down into a collection of
> vectors of 100-125 values each.  I would like to test the normality of the
> vectors and compare them.  In the interactive mode I can test any one
> vector
> using the Shapiro-Wilk test or the Kolmogorov-Smirnov test.  My problem is
> that when I try to write out the results to a file, the term output is a
> mixture of alpha characters along with the number value that I really want.
> How can I get it to write out just the p-values by themselves?
>
> Thank you very much for your time.
>
> Bruce Kindseth
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Tell the difference between characters

2011-04-26 Thread Jorge Ivan Velez
Hi Lisa,

Is this what you have in mind?

> temp <- c("aa", "aA", "ab")
> temp == temp[1]
[1]  TRUE FALSE FALSE

HTH,
Jorge


On Tue, Apr 26, 2011 at 2:09 PM, Lisa <> wrote:

> Dear all,
>
> I just want to determine if the characters in a character string are the
> same or not. For example,
>
> temp <- c("aa", "aA", "ab")
>
> How do I determine the first one have the two same “a”, and the second and
> third have the different characters? Thanks in advance.
>
> Lisa
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Tell-the-difference-between-characters-tp3476130p3476130.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Problem having tick marks aligned when plotting three graphs on top of one another.

2011-04-22 Thread Jorge Ivan Velez
Hi Dr. Sorkin,

One way of doing what you want is via matplot():

with(d, matplot(Slope, d[, -1], type = 'l', lty = 1))

where "d" is your data.

HTH,
Jorge


On Fri, Apr 22, 2011 at 11:55 PM, John Sorkin <> wrote:

> R 2.10
> Windows 7
>
> I am trying to plot three graphs on top of each other. I need to have the
> axises perfectly aligned. For some reason the ticks on the y axes are
> slightly off so they do not perfectly align. Can someone tell me how I can
> get the to overlay each other perfectly? I thought the yaxp parameter would
> solve my problem, but it does not. My data and code follows:
>
> > summaryresults[1:20,]
>  Slope PctCont PctCat PctTTst
>  [1,]  0.05 7.45.6 6.3
>  [2,]  0.1017.7   11.313.3
>  [3,]  0.1532.7   18.725.6
>  [4,]  0.2053.3   27.540.2
>  [5,]  0.2572.1   41.254.5
>  [6,]  0.3085.5   52.970.8
>  [7,]  0.3593.9   65.283.6
>  [8,]  0.4097.0   73.689.9
>  [9,]  0.4599.7   84.896.5
> [10,]  0.5099.9   90.198.4
> [11,]  0.55   100.0   93.299.7
> [12,]  0.60   100.0   97.399.8
> [13,]  0.65   100.0   98.8   100.0
> [14,]  0.70   100.0   99.4   100.0
> [15,]  0.75   100.0   99.8   100.0
> [16,]  0.80   100.0   99.7   100.0
> [17,]  0.85   100.0  100.0   100.0
> [18,]  0.90   100.0  100.0   100.0
> [19,]  0.95   100.0  100.0   100.0
> [20,]  1.00   100.0  100.0   100.0
> >
> plot(summaryresults[,"Slope"],summaryresults[,"PctCont"],type="b",yaxp=c(0,100,10))
> > par(new=TRUE)
> >
> plot(summaryresults[,"Slope"],summaryresults[,"PctCat"],type="b",yaxp=c(0,100,10))
> > par(new=TRUE)
> >
> plot(summaryresults[,"Slope"],summaryresults[,"PctTTst"],type="b",yaxp=c(0,100,10))
>
>
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:13}}

__
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] indexing list elements with lapply?

2011-04-22 Thread Jorge Ivan Velez
Dear Simon,

Try any of the following:

sapply(r, function(l) l[,2] / l[1, 2])
lapply(r, function(l) l[,2] / l[1, 2])

HTH,
Jorge


On Fri, Apr 22, 2011 at 5:52 PM, Simon Kiss <> wrote:

> Dear colleagues,
> I have a list that looks like what the code below produces.  I  need a
> function to go through each list element and work on the second column of
> each list element (the first column is irrelevant to me...if the proposed
> function works on the first column as a consequence of a writing something
> simple, that's fine).
> I need to index the second column of each list element to the first item in
> each column.  So for each list, I need to divide each number in the second
> column by the first number in that column.
>
> This code does what I want, but it only works on one item in the list
> r[[1]][,2] / r[[1]][1,2].
>
> I've tried working with this function but can't get it to work:
> f<-function(x) {
> for (i in 1:5)
> {
>
> x[[i]][,2]/x[[i]][1,2]
> }
> }
>
> lapply(r, f)
>
> But I get this error message:
> Error in x[[i]][, 2] : incorrect number of dimensions
>
> Hope someone can help. I'm grateful for any suggestions.
> Yours, Simon Kiss
>
> **dataset
>
> ff<-runif(10, 0.85, 1)
> ff<-cbind(ff, 1-ff)
> gg<-runif(10, 0.85, 1)
> gg<-cbind(gg, 1-ff)
> hh<-runif(10, 0.86, 1)
> hh<-cbind(hh, 1-hh)
> ii<-runif(10, 0.92, 1)
> ii<-cbind(ii, 1-ii)
> jj<-runif(10,0.76, 1)
> jj<-cbind(jj, 1-jj)
> r<-list(ff, gg, hh,ii, jj)
> *
> Simon J. Kiss, PhD
> Assistant Professor, Wilfrid Laurier University
> 73 George Street
> Brantford, Ontario, Canada
> N3T 2C9
> Cell: +1 519 761 7606
>
> __
> 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] all combinations with replacement

2011-04-21 Thread Jorge Ivan Velez
Hi Kehl,

How large are n and k in your case?  Using Dimitris' approach and I got the
following timings for 1000 replicates:

# function based on Dimitri's reply
foo <- function(n, k){
  r <- expand.grid(rep(list(0:n), k))
   subset(r, rowSums(r) == n)
  }

# a second try
foo2 <- function(n, k){
  r <- expand.grid(rep(list(0:n), k))
 r[rowSums(r) == n, ]
  }

# n = 6, k = 3
> system.time(replicate(1000, foo(6, 3)))
   user  system elapsed
  1.336   0.015   1.345

> system.time(replicate(1000, foo2(6, 3)))
   user  system elapsed
  1.210   0.008   1.209

HTH,
Jorge

> R.version
   _
platform   x86_64-apple-darwin9.8.0
arch   x86_64
os darwin9.8.0
system x86_64, darwin9.8.0
status Patched
major  2
minor  13.0
year   2011
month  04
day18
svn rev55504
language   R
version.string R version 2.13.0 Patched (2011-04-18 r55504)


On Thu, Apr 21, 2011 at 3:52 PM, Kehl Dániel <> wrote:

> Thank you.
> I only need those where the rowsum = n.
> I could choose those with code, but I dont think it is efficient that way.
>
> daniel
>
> 2011-04-21 12:33 keltezéssel, Dimitris Rizopoulos írta:
>
>
>> expand.grid(rep(list(0:6), 3))
>>
>
> __
> 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] line type lty

2011-04-21 Thread Jorge Ivan Velez
See ?par

Best,
Jorge


On Thu, Apr 21, 2011 at 12:22 PM, Hui Du <> wrote:

> Hi All,
>
>
>Does somebody know how to know the detail of the line types?
> For example, lty = 1, means what kind of line?, lty = 2, means what kind of
> line?
>
>
>Thanks.
>
> HXD
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Find characters in a matrix and return a TRUE-FALSE vector

2011-04-13 Thread Jorge Ivan Velez
Hi Nina,

You might try

sapply(yourdata, function(x) any(x == "C"))

See ?sapply for more details.

HTH,
Jorge


On Wed, Apr 13, 2011 at 7:17 AM, Vitrifizierung <> wrote:

> I have the following problem:
>
> My data is a matrix of multiple columns and rows. The column I am
> interested
> in looks like that (I think it is a column in a matrix that contains a
> vector each?):
>
> [[1]]
> [1] A B C
> [4] D E
>
> [[2]]
> [1] A D E
>
> [[3]]
> [1] C E F
> [4] G
>
> I now want to look for a special word (for example C; in my case the single
> entries are words, not single letters) and return a vector, like
>
> [1] TRUE FALSE TRUE
>
> Is there an easy way to do it?
> Sorry, I am really a beginner and I did not really solve the problem by
> looking into other threads...
>
> Thanks a lot,
> Nina
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Find-characters-in-a-matrix-and-return-a-TRUE-FALSE-vector-tp3446868p3446868.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Dump the "source code" of data frame

2011-04-13 Thread Jorge Ivan Velez
Hi CH,

Take a look at  ?dput

HTH,
Jorge


On Wed, Apr 13, 2011 at 3:09 AM, C.H. <> wrote:

> Dear R experts,
>
> I remember a similar function existed and have been mentioned in
> R-help before. I tried my best to search but I really can't find it
> out.
>
> suppose I have an data frame like this:
>
> > somedata <- data.frame(age.min = 1, age.max = 1.5, male = TRUE, l =
> -1.013, m=16.133, s=0.07656)
>
> In order to back up the data and I don't want to use write.table(), I
> would like to back up the "source code" of the data frame. When I
> apply that function (let's call it dumpdf() ), the function will
> reproduce the "source code" that creates the data.frame. For example:
>
> > dumpdf(somedata)
> somedata <- data.frame(age.min = 1, age.max = 1.5, male = TRUE, l =
> -1.013, m=16.133, s=0.07656)
>
> Is there any function similar to the dumpdf() above?
>
> Thank you so much!
>
> Regards,
>
> CH
>
> --
> CH Chan
>
> __
> 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] list to data frame

2011-04-10 Thread Jorge Ivan Velez
Hi Franklin,

Try

do.call(rbind, ineffFilesList)

See ?do.call for more details.

HTH,
Jorge


On Sun, Apr 10, 2011 at 2:01 PM, Franklin Tamborello II <> wrote:

> I need to make a data frame out of the data that I currently have in a
> list. This works, but is ugly:
> ineffData<-rbind(ineffFilesList[[1]], ineffFilesList[[2]],
> ineffFilesList[[3]], ineffFilesList[[4]], ineffFilesList[[5]],
> ineffFilesList[[6]], ineffFilesList[[7]], ineffFilesList[[8]],
> ineffFilesList[[9]], ineffFilesList[[10]], ineffFilesList[[11]],
> ineffFilesList[[12]], ineffFilesList[[13]], ineffFilesList[[14]],
> ineffFilesList[[15]], ineffFilesList[[16]], ineffFilesList[[17]],
> ineffFilesList[[18]], ineffFilesList[[19]], ineffFilesList[[20]],
> ineffFilesList[[21]], ineffFilesList[[22]], ineffFilesList[[23]],
> ineffFilesList[[24]], ineffFilesList[[25]], ineffFilesList[[26]],
> ineffFilesList[[27]])
>
>
> What's an efficient way of doing this such that the computer will do the
> work of recurring through the list of elements of ineffFilesList?
>
> Much appreciation,
>
>
>
>
> Frank Tamborello, PhD
> W. M. Keck Postdoctoral Fellow
> School of Biomedical Informatics
> University of Texas Health Science Center at Houston
>
> __
> 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] Getting number of students with zeroes in long format

2011-04-08 Thread Jorge Ivan Velez
Hi Chris,

Sorry for the late response.  The following selects all students that have
never been suspended:

> with(susim, tapply(sus, id_r, function(x) all(x == 0)))
999881 999886 999890 999892 999896 999897
 FALSE   TRUE   TRUE   TRUE  FALSE   TRUE

> r <- with(susim, tapply(sus, id_r, function(x) all(x == 0)))

> names(r)[r == FALSE]   # id_r
[1] "999881" "999896"

> susim[! susim$id_r %in% names(r)[r == FALSE], ]
   id_r sus
999886.5 999886   0
999886.6 999886   0
999886.7 999886   0
999886.8 999886   0
999890.5 999890   0
999890.6 999890   0
999890.7 999890   0
999890.8 999890   0
999892.5 999892   0
999892.6 999892   0
999892.7 999892   0
999892.8 999892   0
999897.5 999897   0
999897.6 999897   0
999897.7 999897   0


HTH,
Jorge


On Thu, Apr 7, 2011 at 9:07 AM, Christopher Desjardins <> wrote:

> Hi Jorge,
> I want to make sure this does what I want.
>
> So I want to get a count of students that never get a suspension. Once a
> student has a non-zero I don't want to count that student. Each id_r is may
> be associated with multiple sus. Are these commands doing this? Because ...
>
> > suslm[175953:nrow(suslm),c("id_r","sus")]
>id_r  sus
> 999881.5 999881   1
> 999881.6 999881   7
> 999881.7 999881   0
> 999881.8 999881   0
> 999886.5 999886   0
> 999886.6 999886   0
> 999886.7 999886   0
> 999886.8 999886   0
> 999890.5 999890   0
> 999890.6 999890   0
> 999890.7 999890   0
> 999890.8 999890   0
> 999892.5 999892   0
> 999892.6 999892   0
> 999892.7 999892   0
> 999892.8 999892   0
> 999896.5 999896   0
> 999896.6 999896   4
> 999896.7 999896   3
> 999896.8 999896   0
> 999897.5 999897   0
> 999897.6 999897   0
> 999897.7 999897   0
> >
> > tail(with(suslm,tapply(sus,id_r,function(x) any(x==0
> 999881 999886 999890 999892 999896 999897
>   TRUE   TRUE   TRUE   TRUE   TRUE   TRUE
> > r <- with(suslm, tapply(sus, id_r, function(x) any(x > 0))
> > tail(with(suslm, tapply(sus, id_r, function(x) any(x > 0
> 999881 999886 999890 999892 999896 999897
>   TRUE  FALSE  FALSE  FALSE   TRUE  FALSE
>
> Based on this 999881 and 999896 should be FALSE not TRUE
>
> I would expect if they were true for the first command they should be false
> for the second command right?
>
> > tail(names(r[ r == TRUE ]))
> [1] "999752" "999767" "999806" "999807" "999881" "999896"
> > tail(names(r[ r == FALSE ]))
> [1] "999869" "999870" "999886" "999890" "999892" "999897"
>
> This command seems to do the right thing. Is that right?
>
>
> On Wed, Apr 6, 2011 at 10:25 PM, Jorge Ivan Velez <> wrote:
>
>> Hi Chris,
>>
>> Sorry I did not see your email before ;-)   Here is one option:
>>
>> >  r <- with(d, tapply(sus, id_r, function(x) any(x > 0)))
>> > r
>>1115    16    18    1920212224252630
>>  3132
>> FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
>> FALSE FALSE
>>33
>> FALSE
>> > names(r[ r == TRUE ])
>> [1] "15" "25"
>>
>> Regards,
>> Jorge
>>
>>
>> On Wed, Apr 6, 2011 at 5:03 PM, Christopher Desjardins <> wrote:
>>
>>>  Thanks. And how many could I find that have greater than 0?
>>> Chris
>>>
>>>
>>> On Wed, Apr 6, 2011 at 3:58 PM, Jorge Ivan Velez <> wrote:
>>>
>>>> Hi Chris,
>>>>
>>>> Is this what you have in mind?
>>>>
>>>> > sum(with(yourdata, tapply(sus, id_r, function(x) any(x==0
>>>> [1] 13
>>>>
>>>> HTH,
>>>> Jorge
>>>>
>>>>
>>>> On Wed, Apr 6, 2011 at 4:44 PM, Christopher Desjardins <> wrote:
>>>>
>>>>> Hi,
>>>>> I have longitudinal school suspension data on students. I would like to
>>>>> figure out how many students (id_r) have no suspensions (sus), i.e.
>>>>> have a
>>>>> code of '0'. My data is in long format and the first 20 records look
>>>>> like
>>>>> the following:
>>>>>
>>>>> > suslm[1:20,c(1,7)]
>>>>>   id_r sus
>>>>>   11   0
>>>>>   15  10
>>>>>   16   0
>>>>>   18   0
>>>>>   19   0
>>>>>   19   0
>>>>>   20   0
>>>>>   21   0
>>>>>   21   0
>>>>>   22   0
>>>>>   24   0
>>>>>   24   0
>>>>>   25   3
>>>>>   26   0
>>>>>   26   0
>>>>>   30   0
>>>>>   30   0
>>>>>   31   0
>>>>>   32   0
>>>>>   33   0
>>>>>
>>>>> Each id_r is unique and I'd like to know the number of id_r that have a
>>>>> 0
>>>>> for sus not the total number of 0. Does that make sense?
>>>>> Thanks!
>>>>> Chris
>>>>>
>>>>>[[alternative HTML version deleted]]
>>>>>
>>>>> __
>>>>> R-help@r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>>> PLEASE do read the posting guide
>>>>> http://www.R-project.org/posting-guide.html
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>
>>>>
>>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Correlation Matrix

2011-04-07 Thread Jorge Ivan Velez
I am sorry for the noise, but

with(MyDataFrame[, 1:3])

should have been

with(cor(MyDataFrame[, 1:3]))

Best,
Jorge



On Thu, Apr 7, 2011 at 3:21 PM, Jorge Ivan Velez <> wrote:

> Hi Dmitry,
>
> You might try
>
> with(MyDataFrame[, 1:3])
>
> is variable1, variable2 and variable3 correspond to the first three columns
> of your data, or
>
> with( MyDataFrame( cor( cbind( variable1, variable2, variable3) ) ) )
>
> otherwise.
>
> HTH,
> Jorge
>
>
>
> On Thu, Apr 7, 2011 at 3:09 PM, Dmitry Berman <> wrote:
>
>> Listers,
>>
>> I have a question regarding correlation matrices. It is fairly straight
>> forward to build a correlation matrix of an entire data frame. I simply
>> use
>> the command cor(MyDataFrame). However, what I would like to do is
>> construct
>> a smaller correlation matrix using just three of the variable out of my
>> data
>> set.
>>
>> When I run this:
>> cor(MyDataFrame$variable1, MyDataFrame$variable2,MyDataFrame$variable3) I
>> get an error.
>>
>> Is there a way to do this through a built in function or is this something
>> I
>> have to construct manually?
>>
>> Thanks
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[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] Correlation Matrix

2011-04-07 Thread Jorge Ivan Velez
Hi Dmitry,

You might try

with(MyDataFrame[, 1:3])

is variable1, variable2 and variable3 correspond to the first three columns
of your data, or

with( MyDataFrame( cor( cbind( variable1, variable2, variable3) ) ) )

otherwise.

HTH,
Jorge



On Thu, Apr 7, 2011 at 3:09 PM, Dmitry Berman <> wrote:

> Listers,
>
> I have a question regarding correlation matrices. It is fairly straight
> forward to build a correlation matrix of an entire data frame. I simply use
> the command cor(MyDataFrame). However, what I would like to do is construct
> a smaller correlation matrix using just three of the variable out of my
> data
> set.
>
> When I run this:
> cor(MyDataFrame$variable1, MyDataFrame$variable2,MyDataFrame$variable3) I
> get an error.
>
> Is there a way to do this through a built in function or is this something
> I
> have to construct manually?
>
> Thanks
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[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] Selecting data from list object

2011-04-06 Thread Jorge Ivan Velez
Hi Santosh,

One way would be

> sapply(d, "[", 1)
[1] "20110405" "20110405" "20110405" "20110405" "20110405" "20110405"

HTH,
Jorge


On Thu, Apr 7, 2011 at 2:14 AM, santosh <> wrote:

> Hello Group,
>
> Is there a simpler way to get data out of a list object? (like in data
> frame without using the apply functions)
>
> I have the following dataset
>
> > dput(d)
> list(c("20110405", "092102"), c("20110405", "092538"), c("20110405",
> "093458"), c("20110405", "101124"), c("20110405", "102041"),
>c("20110405", "103659"))
>
> I extracted my data like this:
>
> getDate <- function(x)(unlist(x[[1]]))
>
> unlist(lapply(d, getDate))
> [1] "20110405" "20110405" "20110405" "20110405" "20110405" "20110405"
>
> Isn't there an easier way to do this?
>
> Thanks,
> Santosh
>
> __
> 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] force output dimension of table function

2011-04-06 Thread Jorge Ivan Velez
Hi,

You might try

> table(factor(s, levels = 0:5))
0 1 2 3 4 5
0 1 1 1 0 2

HTH,
Jorge


On Wed, Apr 6, 2011 at 11:37 PM, fisken <> wrote:

> I have a small annoying problem.
>
> When I use the 'table' function on a simple vector it counts the
> number of occurences.
> So depending on the values of my input vector the function returns a
> class of type table with different lengths.
>
> Is there an easy way to tell the table function, the values to expect?
>
> That is
> #
> > set.seed(0)
> > s<-sample(0:5,5,rep=T)
> > s
> [1] 5 1 2 3 5
> > ts<-table(s)
> > ts
> s
> 1 2 3 5
> 1 1 1 2
>
> ##
>
> And what I wanted was
>
> 0 1 2 3 4 5
> 0 1 1 1 0 2
>
>
> Thanks
>
> __
> 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] Getting number of students with zeroes in long format

2011-04-06 Thread Jorge Ivan Velez
Hi Chris,

Is this what you have in mind?

> sum(with(yourdata, tapply(sus, id_r, function(x) any(x==0
[1] 13

HTH,
Jorge


On Wed, Apr 6, 2011 at 4:44 PM, Christopher Desjardins <> wrote:

> Hi,
> I have longitudinal school suspension data on students. I would like to
> figure out how many students (id_r) have no suspensions (sus), i.e. have a
> code of '0'. My data is in long format and the first 20 records look like
> the following:
>
> > suslm[1:20,c(1,7)]
>   id_r sus
>   11   0
>   15  10
>   16   0
>   18   0
>   19   0
>   19   0
>   20   0
>   21   0
>   21   0
>   22   0
>   24   0
>   24   0
>   25   3
>   26   0
>   26   0
>   30   0
>   30   0
>   31   0
>   32   0
>   33   0
>
> Each id_r is unique and I'd like to know the number of id_r that have a 0
> for sus not the total number of 0. Does that make sense?
> Thanks!
> Chris
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] round number

2011-03-26 Thread Jorge Ivan Velez
Hi Alfredo,

Try

noquote(sprintf("%.2f", a*.2))

HTH,
Jorge


On Sat, Mar 26, 2011 at 2:05 PM, Alfredo Alessandrini <> wrote:

> Hi,
>
> > a <- 4
>
> > a*0.2
> [1] 0.8
>
> ok!!
>
> Is there a method to obtain this:
>
> > a*0.2
> [1] 0.80
>
> I need to round the number also with the zero.
>
>
>
> Thanks in advance,
>
> Alfredo
>
> __
> 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] "for" loop assistance -

2011-03-25 Thread Jorge Ivan Velez
Hi Steven,

One would be

with(yourdataset, aggregate(x, list(lc1, id), mean))
Group.1 Group.2x
1   85 ga1 45.47261
2   95 ga1 53.38831
3  105 ga1 58.18282
4  115 ga1 63.77469
5  125 ga1 66.98222
6   85 ga2 47.55711
7   95 ga2 54.78450
8  105 ga2 60.67968
9  115 ga2 64.83192
10 125 ga2 66.98222
11  85 ga3 51.99211
12  95 ga3 56.70202
13 105 ga3 61.69574
14 115 ga3 65.90707
15 125 ga3 66.98222

HTH,
Jorge


On Fri, Mar 25, 2011 at 1:36 PM, Steven Ranney <> wrote:

> All –
>
> I have an example data frame
>
> x   lc1 id
> 43.38812035 85  ga1
> 47.5571066185  ga1
> 47.5571066185  ga2
> 47.5571066185  ga2
> 51.9921142985  ga3
> 51.9921142985  ga3
> 51.9921142995  ga1
> 54.78449958 95  ga1
> 54.78449958 95  ga2
> 54.78449958 95  ga2
> 56.70201864 95  ga3
> 56.70201864 95  ga3
> 56.70201864 105 ga1
> 59.66361903 105 ga1
> 59.66361903 105 ga2
> 61.69573564105 ga2
> 61.69573564105 ga3
> 61.69573564105 ga3
> 63.77469479 115 ga1
> 63.77469479 115 ga1
> 64.83191994 115 ga2
> 64.83191994 115 ga2
> 64.83191994 115 ga3
> 66.98222118115 ga3
> 66.98222118125 ga1
> 66.98222118125 ga1
> 66.98222118125 ga2
> 66.98222118125 ga2
> 66.98222118125 ga3
> 66.98222118125 ga3
>
> and I’m trying to extract means for every lc1 and id level so that I
> would have a data frame that looks like
>
> x.m lc1 id
> x.1 085 ga1
> x.2 085 ga2
> x.3 085 ga3
> x.4 095 ga1
> x.5 095 ga2
> x.6 095 ga3
> x.7 105 ga1
> x.8 105 ga2
> x.9 105 ga3
> x.10115 ga1
> x.11115 ga2
> x.12115 ga3
> x.13125 ga1
> x.14125 ga2
> x.15125 ga3
>
> Now, I can use brute force to get the second data frame by
>
> write.table(tapply(x[lc1=="085"], id[lc1=="085"], mean), "file.xls",
> sep=",")
> write.table(tapply(x[lc1=="095"], id[lc1=="095"], mean), “file.xls",
> sep=",", append=T)
> write.table(tapply(x[lc1=="105"], id[lc1=="105"], mean), “file.xls",
> sep=",", append=T)
> etc…
>
> and add the values for the lc1 column in the .xls file until I’ve
> worked my way through every level for lc1 then read the file back into
> R, but this would require a great deal of my time.  (I have 72 levels
> for lc1 and 346 levels for id totalling over 20,000 lines.)
>
> I am confident that there is a simple, more elegant solution available
> to me that I am overlooking.  I am sure that I could use a “for” loop,
> but as someone that is new to R programming, I am unsure of how to go
> about creating the for loop to build the second data frame.  I've
> tried to modify existing for loops that I already have but have been
> unsuccessful.
>
> Do you have any suggestions?
>
> Thank you –
>
> Steven Ranney
>
> __
> 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] error in bargraph.CI {sciplot}

2011-03-24 Thread Jorge Ivan Velez
Hi Barbara,

Works just fine for me:

> require(sciplot)
Loading required package: sciplot
> data(ToothGrowth)

# Two-way design with options
bargraph.CI(dose, len, group = supp, data = ToothGrowth,
   xlab = "Dose", ylab = "Growth", cex.lab = 1.5, x.leg = 1,
   col = "black", angle = 45, cex.names = 1.25,
   density = c(0,20), legend = TRUE)

> sessionInfo()
R version 2.11.1 Patched (2010-05-31 r52180)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] sciplot_1.0-7

loaded via a namespace (and not attached):
[1] tools_2.11.1


What OS, R and sciplot versions are you using?

HTH,
Jorge


On Thu, Mar 24, 2011 at 8:35 PM, barbara costa <> wrote:

> Hi to all,
>
> Does anybody knows why this is giving an error?
>
>
> data(ToothGrowth)
>
> # Two-way design with options
> bargraph.CI(dose, len, group = supp, data = ToothGrowth,
>xlab = "Dose", ylab = "Growth", cex.lab = 1.5, x.leg = 1,
>col = "black", angle = 45, cex.names = 1.25,
>density = c(0,20), legend = TRUE)
> Error in dn.call[[1]] : subscript out of bounds
>
> It is the example on bargraph.CI function page
> http://127.0.0.1:16950/library/sciplot/html/bargraph.CI.html
>
>
> Thanks a lot,
> Cheers
> Barbara
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] tapply with specific quantile value

2011-03-24 Thread Jorge Ivan Velez
Hi Steven,

See the prob argument under ?quantile.  The following should be what you
want:

tapply(x, l.c.1, quantile, prob = 0.75)


HTH,
Jorge
*

*

On Thu, Mar 24, 2011 at 7:18 PM, Steven Ranney <> wrote:

> All -
>
> I have an example data frame
>
> x   l.c.1
> 43.38812035 085
> 47.55710661085
> 47.55710661085
> 51.99211429085
> 51.99211429095
> 54.78449958 095
> 54.78449958 095
> 56.70201864 095
> 56.70201864 105
> 59.66361903 105
> 61.69573564105
> 61.69573564105
> 63.77469479 115
> 64.83191994 115
> 64.83191994 115
> 66.98222118115
> 66.98222118125
> 66.98222118125
> 66.98222118125
> 66.98222118125
>
> and I'd like to get the 3rd quantile by l.c.1 so I use
>
> tapply(x, l.c.1, quantile)
>
> and my output includes all quantiles (i.e., 0, 25%, 50%, 75%, 100%)
> but I'm only interested in the 75% quantile.  Is there an additional
> statement or function I can use to get just the quantile that I want?
>
> Thanks for your help -
>
> SR
> Steven H. Ranney
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How create vector that sums correct responses for multiple subjects?

2011-03-24 Thread Jorge Ivan Velez
Hi Kevin,

Try this (untested):

sapply(split(pretestdata, Subject), function(l) with(l$Correct == "C"))

HTH,
Jorge


On Thu, Mar 24, 2011 at 3:24 PM, Kevin Burnham <> wrote:

> I have a data file with indicates pretest scores for a linguistics
> experiment.  The data are in long form so for each of 33 subjects there are
> 400 rows, one for each item on the test, and there is a column called
> ‘Correct’ that shows ‘C’ for a correct response and ‘E’ for an incorrect
> response.  I am trying to write a formula that will create a vector that
> indicates the number of correct answers for each subject.
>
>
>
> The following:
>
>
>
> nrow(pretestdata[(pretestdata$Subject=="1" & pretestdata$Correct=="C"),])
>
>
>
> gives the number of correct responses for subject 1, but I would like a
> vector that indicates the number correct for each of 33 subjects.
>
>
>
>  Thank you sincerely for your assistance.
>
>
>
> Kevin Burnham
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] apply mean to a three-dimension data

2011-03-24 Thread Jorge Ivan Velez
Hi Hui,

Ssee ?Reduce for more details.  You might try something along the lines of

> mymean <- function(x) Reduce("+", x)/length(x)
> add(b)
 [,1] [,2]
[1,] 10.3 12.3
[2,] 11.3 13.3

HTH,
Jorge


On Thu, Mar 24, 2011 at 11:07 AM, Hui Du <> wrote:

> Hi All,
>
>Suppose I have data like
>
> b[[1]] = matrix(1:4, 2, 2)
> b[[2]] = matrix(10:13, 2, 2)
> b[[3]] = matrix(20:23, 2, 2)
>
> [[1]]
> [,1] [,2]
> [1,]13
> [2,]24
>
> [[2]]
> [,1] [,2]
> [1,]   10   12
> [2,]   11   13
>
> [[3]]
> [,1] [,2]
> [1,]   20   22
> [2,]   21   23
>
>Now I want to calculate the mean of each cell across the
> list. For example mean of (b[[1]][1,1], b[[2]][1,1], b[[3]][1,1]), mean of
> (b[[1]][1,2], b[[2]][1,2], b[[3]][1,2]) etc. e.g. mean of (1, 10, 20), mean
> of(3, 12, 22). Could somebody tell me how to do it? Thank you in advance.
>
> HXD
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] apply mean to a three-dimension data

2011-03-24 Thread Jorge Ivan Velez
Sorry, the above should have been

> mymean <- function(x) Reduce("+", x)/length(x)
> mymean(b)
 [,1] [,2]
[1,] 10.3 12.3
[2,] 11.3 13.3

Apologies for the noise.

Best,
Jorge


On Thu, Mar 24, 2011 at 3:54 PM, Jorge Ivan Velez <> wrote:

> Hi Hui,
>
> Ssee ?Reduce for more details.  You might try something along the lines of
>
> > mymean <- function(x) Reduce("+", x)/length(x)
> > add(b)
>  [,1] [,2]
> [1,] 10.3 12.3
> [2,] 11.3 13.3
>
> HTH,
> Jorge
>
>
> On Thu, Mar 24, 2011 at 11:07 AM, Hui Du <> wrote:
>
>> Hi All,
>>
>>Suppose I have data like
>>
>> b[[1]] = matrix(1:4, 2, 2)
>> b[[2]] = matrix(10:13, 2, 2)
>> b[[3]] = matrix(20:23, 2, 2)
>>
>> [[1]]
>> [,1] [,2]
>> [1,]13
>> [2,]24
>>
>> [[2]]
>> [,1] [,2]
>> [1,]   10   12
>> [2,]   11   13
>>
>> [[3]]
>> [,1] [,2]
>> [1,]   20   22
>> [2,]   21   23
>>
>>Now I want to calculate the mean of each cell across the
>> list. For example mean of (b[[1]][1,1], b[[2]][1,1], b[[3]][1,1]), mean of
>> (b[[1]][1,2], b[[2]][1,2], b[[3]][1,2]) etc. e.g. mean of (1, 10, 20), mean
>> of(3, 12, 22). Could somebody tell me how to do it? Thank you in advance.
>>
>> HXD
>>
>>[[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Urgent query about R!

2011-03-22 Thread Jorge Ivan Velez
Hi Rachel,

You might also try

apply(expand.grid(rep(list(1:6), 4)), 1, paste, collapse = "", sep = "")

HTH,
Jorge
*


*
On Tue, Mar 22, 2011 at 6:41 PM, Rachel Chu <> wrote:

> Hi there,
>
> I am currently working on a R programming project and got stuck.
> I am supposed to generate a set of possibilities of 1296 different
> combinations of 4 numbers, ie. , 1234, 2361, (only contain 1 to 6) in a
> matrix form
> here is what I got which has not been working as it keeps coming out with
> the same number on the row..
>
> The code:
> gl1<- gl(1296,1,length=1296, labels=1:1296, ordered=true)
> s<-matrix(gl1, nrow=1296,ncol=4)
>
> and i want to get a result which will provide me 1296 outcomes of DIFFERENT
> COMBINATIONS of numbers (from 1 to 6)
> e.g.
> [1] 
> ...
> [1295] 6665
> [1296] 
>
> if anyone could email me back with what I am doing wrong and what I should
> actually do i would be extremely thankful!
> (I am doing my project and am so stressed because of getting stuck on the
> supposedly easier problem..)
>
> Thanks again!
>
> xoxo
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing Period in String

2011-03-20 Thread Jorge Ivan Velez
Hi John,

Try

gsub("[.]","",txt)

See "Extended Regular Expressions" in ?regex.

HTH,
Jorge
*

*

On Mon, Mar 21, 2011 at 12:49 AM, Sparks, John James <> wrote:

> Dear R Users,
>
> I am working with gsub for the first time.  I am trying to remove some
> characters from a string.  I have hit the problem where the period is the
> shorthand for 'everything' in the R language when what I want to remove is
> the actual periods.  In the example below, I simply want to remove the
> periods as I have removed the comma, but instead the complete string is
> wiped out.  I would appreciate it if someone could let me know how I
> communicate that I want to remove the period verbatim to R.
>
> Many thanks.
> --John Sparks
>
> > txt="This is a test. However, it is only a test."
> > txt2<-gsub(",","",txt)
> > txt2
> [1] "This is a test. However it is only a test."
> > txt3<-gsub(".","",txt)
> > txt3
> [1] ""
> >
>
> __
> 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] Output a table formatted with standard deviations below means

2011-03-19 Thread Jorge Ivan Velez
Hi Nathan,

Do not know a direct way, but the following seems to work:

# data
means <- matrix(1:10,nrow=2)
sds <- matrix(seq(0.1,1,by=0.1),nrow=2)
colnames(means) <- colnames(sds) <- c("a","b","c","d","e")

# adding "( )" to the SDs
sdsn <- t(apply(sds, 1, function(x) paste('(', x, ')', sep = "")))

# formatting
res <- do.call(rbind, lapply(1:nrow(means), function(i) rbind(means[i, ],
sdsn[i, ])))
res

# LaTeX
require(xtable)
xtable(res)

*HTH,*
*Jorge*
*
*

On Sat, Mar 19, 2011 at 12:13 PM, Nathan Torrance <> wrote:

> Is it in bad form to double post to StackOverflow and R-help? Apologies if
> so. Here's my task:
>
> I've got a matrix of means like so
>
> means<-matrix(1:10,nrow=2)
> colnames(means)<-c("a","b","c","d","e")
>
> and a matrix of standard deviations like so
>
> sds<-matrix(seq(0.1,1,by=0.1),nrow=2)
> colnames(sds)<-c("a","b","c","d","e")
>
> and I want to output a Latex (or HTML) table where the standard deviations
> appear in parens just below the corresponding means.
>
> Something like this:
>
>a&   b&  c&  d&  e \\
>1&   3&  5&  7&  9 \\
>  (0.1)  &  (0.3) & (0.5) & (0.7) & (0.9) \\
>2&   4&  6&  8&  10 \\
>  (0.2)  &  (0.4) & (0.6) & (0.8) & (1.0) \\
>
> except in proper Latex (or HTML).
>
> How can I do this from R?
>
> Someone mentioned the "apsrtable" package but that seems to require my
> having a model object.
>
> Thanks in advance folks.
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Differences per group

2011-03-09 Thread Jorge Ivan Velez
Hi Rens,

One way would be

x$difference <- do.call(c, with(x, tapply(amount, customer, function(x) c(0,
diff(x)
x

Take a look at ?tapply and ?aggregate for more information.

HTH,
Jorge


On Wed, Mar 9, 2011 at 10:27 AM, rens_1112 <> wrote:

> Dear all,
>
> Probably a rather stupid question, but I couldn't find the answer..
>
> I currently have a dataframe with customers' id's and purchase amount, what
> I would like to do is to show the difference between amount purchased
> compared to the month before per customer.
>
> I have made some attempts myself using diff, but what i can not get to work
> is that each different customer starts with a 0.
>
> This is an example of what I have:
>
> >purchase_amount
> customeramount
> 123 6
> 123 5
> 123 9
> 123 8
> 123 11
> 123 7
> 230 19
> 230 18
> 230 12
> 230 17
> 380 7
> 380 9
> 380 2
> 380 7
> 380 8
> 380 8
> 380 6
> 380 8
>
> How I would like it to look like:
>
> customeramount  difference
> 123 6   0
> 123 5   -1
> 123 9   4
> 123 8   -1
> 123 11  3
> 123 7   -4
> 230 19  0
> 230 18  -1
> 230 12  -6
> 230 17  5
> 380 7   0
> 380 9   2
> 380 2   -7
> 380 7   5
> 380 8   1
> 380 8   0
> 380 6   -2
> 380 8   2
>
> I hope my question is clear like this.
> Many thanks in advance
> Rens
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Differences-per-group-tp3343800p3343800.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Loop Through Columns to Remove Rows

2011-03-09 Thread Jorge Ivan Velez
Hi Sam,

How about this?

test[apply(test, 1, function(x) !any(x == '#DIV/0!')), ]

HTH,
Jorge


On Wed, Mar 9, 2011 at 3:29 PM, Sam Albers <> wrote:

> Hello Venerable List,
>
> I am trying to loop (I think) an operation through a list of columns in a
> dataframe to remove set of #DIV/0! values. I am trying to do this like so:
>
> #Data.frame
> test <- read.csv("http://dl.dropbox.com/u/1574243/sample_data.csv";,
> header=TRUE, sep=",")
>
>
> #This removes all the rows with #DIV/0! values in the mean column.
> only.mean <- test[!test$mean=="#DIV/0!",]
>
> #This removes the majority of #DIV/0! values as there is a large block of
> these values that extends over every column.
> #However, it doesn't remove then all. Can any recommend a way where I can
> cycle through all the columns and remove these values other than manually
> like so:
> mean.median <- only.mean[!only.mean$median=="#DIV/0!",] # and so on through
> each column?
>
> Can anyone recommend a better way of doing this?
>
> Thanks in advance!
>
> Sam
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multiple testing corrections on very large vector

2011-03-09 Thread Jorge Ivan Velez
Hi terdon,

Very happy to help and know it worked.

Honestly, I do not know exactly where the differences are, but it is not
hard to check the sources and compare both algorithms. When doing this, you
can can see that p.adjust() uses vectorization whereas mt.rawp2adjp() does
not. Perhaps that is the key for the timing differences you observed.

# checking the sources
require(multtest)
mt.rawp2adjp
p.adjust

Best,
Jorge


On Tue, Mar 8, 2011 at 12:33 PM, terdon <> wrote:

> Hi Jorge,
>first of all THANKS! I just ran you suggestion and got blown away:
>
>  system.time(res <- p.adjust(pv, method = 'fdr'))
>   user  system elapsed
>  55.052   3.100  62.560
>
> I had tried the same thing using mt.rawp2adjp as per my original post, sent
> it to a cluster here on friday afternoon and it was still not finished (AND
> using ~16GB of memory) three days later. wow.
>
> OK, so, great but what is the difference between mt.rawp2adjp and p.adjust?
> Do you know? Is it a simple difference in how the same algorithm is
> implemented? Is there any reason one would be more trustworthy than the
> other?
>
> And again, thanks, wow...
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Multiple-testing-corrections-on-very-large-vector-tp3341398p3341856.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multiple testing corrections on very large vector

2011-03-08 Thread Jorge Ivan Velez
Hi terdon,

You are absolutely right. I apologize for any inconvenience my lack of
coffee might have caused :-)

I simulated some p-values with the length of your vector and ran the
p.adjust() function on them. Here is what I got:

system.time(res <- p.adjust(pv, method = 'fdr'))
   user  system elapsed
184.529   4.862 192.066

If you wish, I can run that for you on my machine. Below is my sessionInfo()

R version 2.11.1 Patched (2010-05-31 r52180)
x86_64-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] multtest_2.6.0 Biobase_2.8.0

loaded via a namespace (and not attached):
[1] MASS_7.3-7  splines_2.11.1  survival_2.36-2 tools_2.11.1


Best,
Jorge


On Tue, Mar 8, 2011 at 10:37 AM, terdon <> wrote:

> Hi Jorge, and thanks for your answer, it looks promising.
>
> However, I have a question. First of all, I am a lowly biologist so please
> excuse any horrible errors of understanding I may make.
>
> So, the BH correction depends on, among other things, sorting the vector of
> P-values from the smallest to the largest and then multiplying each value
> by
> the length of the vector times its rank.
>
> If I understand correctly, your suggestion is to use  p.adjust on a subset
> of the vector pv, set the n parameter to the length of the entire vector
> and
> then iterate until all P-values have been adjusted.
>
>  Wouldn't I still need to know the rank of each p value in the subset
> vector
> with respect to its position in the original sorted vector? I can see how
> to
> calculate that of course, but how can I give this info to p.adjust if it
> only takes the length of the vector as an argument?
>
> Thanks again
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Multiple-testing-corrections-on-very-large-vector-tp3341398p3341615.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Multiple testing corrections on very large vector

2011-03-08 Thread Jorge Ivan Velez
Hi terdon,

Take a look at ?p.adjust and its argument n.  For example, you could adjust
B pv values by using

p.adjust(pv[1:B], method = 'BH', n = B)

Then, you can continue processing other subsets of pv and concatenate the
result.  Here, a for() loop might be useful.

HTH,
Jorge


On Tue, Mar 8, 2011 at 8:49 AM, terdon <> wrote:

> Hello all,
>  I am calculating probabilities of association for terms in the
> GeneOntology database. I have ~4e7 probabilities and I would like to
> correct
> for multiple testing. At the moment I have something like the following:
>
> pv is a vector containing my 4e7 probabilities.
>
> To run the multiple testing corrections I do:
>
> mt <- mt.rawp2adjp(pv, proc="BH")
>
> Because of the size of the vector this takes a VERY long time and a LOT of
> memory. I cannot split the job into smaller ones since all values in the
> vector are required for the calculation.
>
> Can anyone think of a trick that would allow me to reduce the memory usage
> of this procedure? Or t least make it faster?
>
> Thanks
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Multiple-testing-corrections-on-very-large-vector-tp3341398p3341398.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Sorting

2011-03-07 Thread Jorge Ivan Velez
Hi Whitney,

If I understood correctly, what you actually want is to construct a 2x2
table considering "smoking" and "retlevel". Perhaps something along the
lines of

with(yourdata, table(retlevel, smoking))

could give you some insights.  See ?table for more details.

HTH,
Jorge


On Mon, Mar 7, 2011 at 10:08 PM, Whitney Kistler <> wrote:

> I apologize in advance if this is posted all ready I have not been able to
> find any information about it.  I have this data frame and I want to sort
> smoking by retlevel.
>
> Age Gender   BMI  Calories  Fat Fiber   Alc retlevel
> Smoking
> 164  Female 18.87834   1828.0  63.4  14.7  0.0 Normal
> Non-Smoker
> 225  Female 20.64102   1517.4  59.1   5.9   0.0 Normal  Smoker
> 350  Female 20.40345   1902.9  72.9  35.4  7.3 NormalNon-Smoker
> 432  Female 35.97525   3328.4 163.3  20.0  4.1  High Smoker
> 543  Female 25.58279   2501.6 121.1  19.5  0.0  High Smoker
> 639   Male   21.99912   1951.4   109.1   4.7   0.0 Normal
> Smoker
>
> To get an output like this.
>
> retlevelNormal  High
> Smoking 2 2
> Non-smoker1 1
>
> Thank you very much for your help.
>
> --
> Whitney Kistler M.S.
> Ph.D. Student
> Warnell School of Forestry and Natural Resources
> Southeastern Cooperative Wildlife Disease Study
> University of Georgia
> Athens, GA 30602
> wkist...@uga.edu
> cell:724-309-5298
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] MCMC_glm models

2011-03-07 Thread Jorge Ivan Velez
Hi Nick,

The following would be one way of doing what you want:

# function to estimate one model
foo <- function(mu = 9.244655, n = 50){
 X <- rpois(n, mu)
   glm(X ~ Y, family = poisson)   # note I am using family = poisson
}

B <- 1000  # number of samples  -- change accordingly
Y <- 1960:2009
models <- lapply(1:B, foo)  # a list

To see model 1, type

models[[1]]
summary(models[[1]])  # summary

# coefficients b0 and b1 for all B models
betas <- do.call(rbind, lapply(models, function(m)
summary(m)$coefficients[1:2, 1]))
betas

See ?lapply for more information.  Also, note that by exploring model[[1]]
above, e.g.

str(model[[1]])

as well as

str(summary(models[[1]]))

you can access even more information. See ?glm and ?lm for details,
especially the "Value" section in both.

*
 HTH,
*
Jorge


On Mon, Mar 7, 2011 at 10:52 PM, Nicholas M. Caruso <> wrote:

> Hello, I am trying to run multiple glm models for a dataset and need some
> help
>
> First, i generated a matrix of abundance for 1 populations based on the
> mean and variance of my dataset
>
> X <- replicate(1, rpois(50, 9.244655))
>
> and entered the years as row names
>
> Y <- c(1960:2009)
> rownames(X)<-Y
>
> Now my issue is that I want to run a glm on each of those columns.  However
> I cannot just run glm(X~Y)
>
> "Error: (subscript) logical subscript too long"
>
> I know I can run individual column glms
>
> X_glm <- glm(X[,1]~Y)
>
> but would rather not do that 1 times.
>
> Any suggestions?
>
> Thank you for any help.
> Nick.
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to reference a package in academical paper

2011-03-07 Thread Jorge Ivan Velez
Hi Jan,

R> citation('RODBC')
To cite package ‘RODBC’ in publications use:

  Brian Ripley and and from 1999 to Oct 2002 Michael Lapsley (2010). RODBC:
ODBC
  Database Access. R package version 1.3-2.
  http://CRAN.R-project.org/package=RODBC

A BibTeX entry for LaTeX users is

  @Manual{,
title = {RODBC: ODBC Database Access},
author = {Brian Ripley and and from 1999 to Oct 2002 Michael Lapsley},
year = {2010},
note = {R package version 1.3-2},
url = {http://CRAN.R-project.org/package=RODBC},
  }

ATTENTION: This citation information has been auto-generated from the
package
DESCRIPTION file and may need manual editing, see ‘help("citation")’ .

*

*
On Mon, Mar 7, 2011 at 4:12 PM, Jan Hornych <> wrote:

> Dear,
>
> I am now writing more formal "academical" paper, and would like to
> reference
> an R package. Do you have any recommendation how to do it?
>
> Taking for instance the RODBC package as an example, how would the
> reference
> look like?
> http://cran.r-project.org/web/packages/RODBC/index.html
>
> Thank you
> Jan
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] displaying label meeting condition (i.e. significant, i..e p value less than 005) in plot function

2011-03-05 Thread Jorge Ivan Velez
Hi Umesh,

You can try something along the lines of:

d <- dataf[dataf$p < 0.05, ]   # p < 0.05
with(d, plot(xvar, p, col = 'white'))
with(d, text(xvar, p, name, cex = .7))

HTH,
Jorge



On Sat, Mar 5, 2011 at 12:29 PM, Umesh Rosyara <> wrote:

> Dear R users,
>
> Here is my problem:
>
> # example data
> name <- c(paste ("M", 1:1000, sep = ""))
> xvar <- seq(1, 1, 10)
> set.seed(134)
> p <- rnorm(1000, 0.15,0.05)
> dataf <- data.frame(name,xvar, p)
> plot (dataf$xvar,p)
> abline(h=0.05)
>
> # I can know which observation number is less than 0.05
> which (dataf$p < 0.05)
> [1]  12  20  80 269 272 338 366 368 397 403 432 453 494 543 592 691 723 789
> 811
> [20] 854 891 931 955
>
> I want to display (label) corresponding names on the plot above:
> means that 12th observation M12, 20th observation M20 and so on. Please
> note
> that I have names not in numerical sequience (rather different names), just
> provided for this example to create dataset easily.
>
> Thanks in advance
>
> Umesh R
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] testing power of correlation

2011-03-05 Thread Jorge Ivan Velez
Hi Anna,

Take a look at

?cor
?cor.test

and http://www.statmethods.net/stats/power.html

HTH,
Jorge


On Sat, Mar 5, 2011 at 3:02 PM, Anna Gretschel <> wrote:

> Dear List,
>
> does anyone know how I can test the strength of a correlation?
>
> Cheers, Anna
>
> __
> 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] Grouping data in ranges in table

2011-03-05 Thread Jorge Ivan Velez
Hi Jason,

Something along the lines of

with(Orange, table(cut(age, breaks = c(118, 664, 1004, 1372, 1582, Inf)),
   cut(circumference, breaks = c(30, 58, 62, 115,
145, 179, 214

should get you started.

HTH,
Jorge


On Sat, Mar 5, 2011 at 5:38 PM, Jason Rupert <> wrote:

> Working with the built in R data set Orange, e.g. with(Orange, table(age,
> circumference)).
>
>
> How should I go about about grouping the ages and circumferences in the
> following ranges and having them display as such in a table?
> age range:
> 118 - 664
> 1004 - 1372
> 1582
>
> circumference range:
> 30-58
> 62- 115
> 120-142
> 145-177
> 179-214
>
> Thanks for any feedback and insights, as I hoping for an output that looks
> something like the following:
>   circumference range
>   30-58 62- 115  145-177
> age range
> 118 - 664 ...
> 1004 - 1372 ...
> 1582
>
>
> Thanks a ton.
>
> __
> 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] Entering table with multiple columns & rows

2011-02-28 Thread Jorge Ivan Velez
Hi Laura,

May be yo meant:

diet <- matrix(c(24,134,9,52,23,72,12,15), ncol = 2, byrow = TRUE) # note
ncol = 2
rownames(diet) <- c("none", "healthy", "unhealthy", "dangerous")
colnames(diet) <- c('Yes', 'No')
diet

HTH,
Jorge


On Mon, Feb 28, 2011 at 9:17 PM, Laura Clasemann <> wrote:

>
> Hi,
>
> I'm having difficulty with getting a table to show with
> multiple rows and columns. Below is the commands that I've typed in and
> errors that I am getting. Thank you.
>
> Laura
>
>
> Table trying to enter:
>
> Diet: Binger-yes:   Binger-No:  Total:
> None 24 134 158
> Healthy 9 52 61
> Unhealthy 23 72 95
> Dangerous 12 15 27
>
>
>
>
>
> > diet=matrix(c(24,134,9,52,23,72,12,15),ncol=4,byrow=TRUE)
> > rownames(diet)=c("none", "healthy", "unhealthy", "dangerous")
> Error in dimnames(x) <- dn :
>  length of 'dimnames' [1] not equal to array extent
> > diet=matrix(c(24,134,9,52,23,72,12,15), ncol=4, byrow=4)
> > rownanes(diet)=c("none", "healthy", "unhealthy", "dangerous")
> Error in rownanes(diet) = c("none", "healthy", "unhealthy", "dangerous") :
>  could not find function "rownanes<-"
> > rownames(diet)=c("none", "healthy", "unhealthy", "dangerous")
> Error in dimnames(x) <- dn :
>  length of 'dimnames' [1] not equal to array extent
> > diet=matrix(c(24,134,9,52,23,72,12,15), ncol=4, byrow=4)
> > rownames(diet)=c("none", "healthy", "unhealthy", "dangerous")
> Error in dimnames(x) <- dn :
>  length of 'dimnames' [1] not equal to array extent
> >
>
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] substract 2 data.frames

2011-02-27 Thread Jorge Ivan Velez
Hi Nicolas,

Try

popn[!rownames(popn) %in% rownames(fish), ]

HTH,
Jorge


On Sun, Feb 27, 2011 at 3:29 PM, Nicolas Gutierrez <> wrote:

> Hi!
>
> I have 2 data.frames: "fish" and "popn":
>
> >fish
>
>   xloc yloc id birth  size weight  energy gonad
> 20   15   15 54   -60 107.9   63.0 15952.9   8.0
> 21   15   15 32   -60 105.1   61.4 15538.8   7.8
> 914   43 96   -60 118.9   69.4 17573.2   8.8
> 71   324 64   -60 121.6   71.0 17976.0   9.0
> 342   64 20   -60 116.2   67.9 17173.0   8.6
> 956   20 58   -60 106.5   62.2 15738.3   7.9
> 977   81 89   -60 104.5   61.1 15449.6   7.7
> 945   30 74   -60 103.0   60.1 15217.1   7.6
> 45   26   28 92   -60  98.6   57.6 14566.2   7.3
> 59   29   37 42   -60  98.1   57.3 14492.0   7.2
>
> >popn
>
>   xloc yloc id birth  size weight  energy gonad
> 20   15   15 54   -60 107.9   63.0 15952.9   8.0#delete
> 21   15   15 32   -60 105.1   61.4 15538.8   7.8#delete
> 904   43 28   -60  74.6   43.6 11027.3   5.5
> 914   43 96   -60 118.9   69.4 17573.2   8.8#delete
> 71   324 64   -60 121.6   71.0 17976.0   9.0#delete
> 342   64 20   -60 116.2   67.9 17173.0   8.6#delete
> 956   20 58   -60 106.5   62.2 15738.3   7.9#delete
> 977   81 89   -60 104.5   61.1 15449.6   7.7#delete
> 945   30 74   -60 103.0   60.1 15217.1   7.6#delete
> 45   26   28 92   -60  98.6   57.6 14566.2   7.3#delete
> 59   29   37 42   -60  98.1   57.3 14492.0   7.2#delete
> 44   25   82 59   -60  97.6   57.0 14427.3   7.2
> 57   29   15 46   -60  96.4   56.3 14252.7   7.1
> 613   80 48   -60  96.4   56.3 14243.3   7.1
> 86   38   67 39   -60  91.3   53.3 13493.6   6.7
>
> And I need to delete the columns in "fish" to the data.frame "popn" as
> follows:
>
> > new.popn
>
>   xloc yloc id birth  size weight  energy gonad
> 904   43 28   -60  74.6   43.6 11027.3   5.5
> 44   25   82 59   -60  97.6   57.0 14427.3   7.2
> 57   29   15 46   -60  96.4   56.3 14252.7   7.1
> 613   80 48   -60  96.4   56.3 14243.3   7.1
> 86   38   67 39   -60  91.3   53.3 13493.6   6.7
>
> And I need this within loops, so I can't do it "manually". Any guidance??
>
> THANKS!
>
> Nico
>
> __
> 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] R in different OS

2011-02-25 Thread Jorge Ivan Velez
Hi Hui,

May be sessionInfo() is what you are looking for. See ?sessionInfo as well
as ?version for more details. You can run the following on your R session
and see what comes up:

sessionInfo()
sessionInfo()$R.version$platform
version$platform

Then, you might use ifelse() to set up the right path.

HTH,
Jorge


On Fri, Feb 25, 2011 at 1:23 PM, Hui Du <> wrote:

> Hi All,
>
>I have two Rs, one has been installed in Windows system and
> another one has been installed under UNIX system. Is there any environmental
> variable or function to tell me which R I am using? The reason that I need
> to know it is under different system, the data path could be different. I
> want to do something like
>
> if it is R under Windows
>
>path = "/ABC"
> else if it is R under UNIX,
>path = "/DEF"
>
> Any idea? Thanks.
>
> Best Regards,
>
> HXD
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] identify an element in a column

2011-02-22 Thread Jorge Ivan Velez
Hi Gary,

Try

transform(z, y = ifelse(x == 5, y-1, y))

HTH,
Jorge

On Tue, Feb 22, 2011 at 12:18 PM, Hongwei Dong <> wrote:

> Hi, R users,
>
> I'm wondering if I can identify an element in a column by an element in
> another column. For example:
>
> x<-1:10
> y<-11:20
> z<-cbind(x,y)
> z
> x  y
>  [1,]  1 11
>  [2,]  2 12
>  [3,]  3 13
>  [4,]  4 14
>  [5,]  5 15
>  [6,]  6 16
>  [7,]  7 17
>  [8,]  8 18
>  [9,]  9 19
> [10,] 10 20
>
> What I want to do is: when x=5, y=y-1
>
> Anyone can tell me how to do this? Thanks.
>
>
> Gary
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] concatenate vector after strsplit()

2011-02-20 Thread Jorge Ivan Velez
Hi Robert,

You might try

do.call(rbind, lapply(yourlist, "[", 1:4))

and then write the resulting file using write.table(...).

Best,
Jorge

On Sun, Feb 20, 2011 at 11:13 AM, Robert Baer <> wrote:

> ls is a list of character vectors created by strsplit()
>
> I want to concatenate  the 1st 4 character elements of each list item as a
> new vector called file.  I admit to being confused about list syntax even
> after numerous readings.
>
> Here's what I tried:
>
> ls <- list(c("Focused", "10k", "A12", "t04.tif", "+", "µm"), c("Focused",
> "10k", "A12", "t08.tif", "+", "µm"), c("Focused", "10k", "A12",
> "t12.tif", "+", "µm"), c("Focused", "10k", "A12", "t16.tif",
> "+", "µm"), c("Focused", "10k", "A12", "t20.tif", "+", "µm"),
>c("Focused", "10k", "A12", "t24.tif", "+", "µm"), c("Focused",
>"10k", "A12", "t36.tif", "+", "µm"), c("Focused", "10k",
>"A12", "t48.tif", "+", "µm"), c("Focused", "10k", "B12",
>"t04.tif", "+", "µm"), c("Focused", "10k", "B12", "t08.tif",
>"+", "µm"))
>
> # Test the waters with one element
> cat(unlist(ls[1])[1:4])  # WHY DOES THE COMMAND PROMPT NOT APPEAR ON
> NEXT LINE AS USUAL???
>
> # Appears to work except for command prompt glitch
>
> # Attempts to use tapply() don't get me anywhere
> file <- tapply(unlist(ls), list(1:length(unlist(ls))),
> cat(unlist(ls[1])[1:4]))
>
> I'm grateful for an approach to putting my vector together, but I'd also
> love to understand the headache I've apparently given the command parser.
>  I'm apparently doing some "no no".
>
> Thanks,
>
> Rob
>
> > R.Version()
> $platform
> [1] "i386-pc-mingw32"
>
> $arch
> [1] "i386"
>
> $os
> [1] "mingw32"
>
> $system
> [1] "i386, mingw32"
>
> $status
> [1] ""
>
> $major
> [1] "2"
>
> $minor
> [1] "12.1"
>
> $year
> [1] "2010"
>
> $month
> [1] "12"
>
> $day
> [1] "16"
>
> $`svn rev`
> [1] "53855"
>
> $language
> [1] "R"
>
> $version.string
> [1] "R version 2.12.1 (2010-12-16)"
>
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Generating uniformly distributed correlated data.

2011-02-19 Thread Jorge Ivan Velez
Hi Soren,

Take a look at http://tolstoy.newcastle.edu.au/R/help/05/07/7741.html

HTH,
Jorge


On Sat, Feb 19, 2011 at 9:17 PM, Søren Faurby <> wrote:

> I wish to generate a vector of uniformly distributed data with a defined
> correlation to another vector
>
> The only function I have been able to find doing something similar is
> corgen from the library ecodist.
>
> The following code generates data with the desired correlation to the
> vector x but the resulting vector y is normal and not uniform distributed
>
> library(ecodist)
> x <- runif(10^5)
> y <- corgen(x=x, r=.5)$y
>
> Do anyone know a similar function generating uniform distributed data or a
> way of transforming y to the desired distribution while keeping the
> correlation between x and y
>
> Kind regards, Soren
>
> __
> 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] questions about counting numbers

2011-02-06 Thread Jorge Ivan Velez
Hi Carrie,

Try

> x <- rle(a)
> rep(x$lengths, x$lengths)
[1] 1 2 2 1

HTH,
Jorge


On Sun, Feb 6, 2011 at 8:21 PM, Carrie Li <> wrote:

> Hello R-helpers,
>
> I have a question about counting numbers.
> Here is a simple example.
>
> a=c(2, 3, 3,4)
> > table(a)
> a
> 2 3 4
> 1 2 1
>
> so, I can to create another variables that has the corresponding counting
> numbers.
> In this case, I want to have:
>
> b=c(1,2,2,1)
>
> Is there any way coding for this ?
>
> Thanks for helps!
>
> Carrie--
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] sum the values in a vector as a complete number

2011-01-31 Thread Jorge Ivan Velez
Hi AD,

You might try the following:

# data
a <- c(2,3,5)
b <- c(8,7)   # you got this wrong ;)

# option 1
foo <- function(x) as.numeric(paste(x, sep = "", collapse = ""))

# examples
foo(a)
# [1] 235
foo(b)
# [1] 87
foo(a) + foo(b)
# [1] 322

# option 2
foo2 <- function(x, y) foo(x) + foo(y)

# example
foo2(a, b)
# [1] 322

See ?paste and ?as.numeric for more information.

HTH,
Jorge

On Mon, Jan 31, 2011 at 11:22 PM, ADias <> wrote:

>
> Hi
>
> I am trying to create a function that is able to calculate this sum:
>
> a<-c(2,3,5)
> b<-(8,7)
>
> with "a" meaning 235 and "b" 87. So the result of this sum would be 235 +
> 87
> = 322.
>
> I've searched a function like strsplit but that worked for integers and in
> reverse - not spliting but combining.
>
> Can you give me a hand on this please?
>
> thanks
> AD
> --
> View this message in context:
> http://r.789695.n4.nabble.com/sum-the-values-in-a-vector-as-a-complete-number-tp3250470p3250470.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] data frame column name change

2011-01-16 Thread Jorge Ivan Velez
Hi eric,

Try

colnames(x)
colnames(x)[1] <- 'newname'
colnames(x)

HTH,
Jorge


On Sun, Jan 16, 2011 at 11:28 PM, eric <> wrote:

>
> How do I change the name of one column in a data frame ? Suppose I have a
> data frame x with 5 columns. If the names were date, col1, col2, col3, col4
> and I wanted to simply change the name of date, what would the command be ?
> I tried the following and it didn't seem to work :
>
> names(x[1]) <- "newname"
>
> Thanks in advance for the comments
> --
> View this message in context:
> http://r.789695.n4.nabble.com/data-frame-column-name-change-tp3220684p3220684.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] standard errors in johansen test

2011-01-12 Thread Jorge Ivan Velez
Hi Walter,

The paper can be found at
http://cran.r-project.org/web/packages/vars/vignettes/vars.pdf  It seems
that you need the "vars" library before trying the function you mention.
 What happens if you do the following?

install.packages("vars")
require(vars)
?cajorls
?ca.jo

HTH,
Jorge


On Wed, Jan 12, 2011 at 10:35 PM, Walter Zhang <> wrote:

> Dear all,
>
>
>
> I have a question. How to get the standard errors of alpha and beta
> when using  "ca.jo" to test cointergration?
>
> In the paper by Bernhard Pfaff and Kronberg im Taunus “VAR, SVAR and SVEC
> Models: Implementation Within R Package”  pp.24-25. The standard errors are
> listed on the table 5 following the code:
>
> R> vecm.r1 <- cajorls(vecm, r = 1)
>
> I tried this in my Mac R, but failed.
>
> Thanks.
>
>
> --
>  Best Regards
>
>  Walter   an ACCA Affiliate (Association of Chartered Certified
> Accountants)
>
>   I COME FROM CHINA
>
>我有一所房子,面朝大海,春暖花开
>
>[[alternative HTML version deleted]]
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] weighed mean of a data frame row-by-row

2011-01-06 Thread Jorge Ivan Velez
Hi Vassilis,

Try

test.df$y <- with(test.df, x1*w + x2*(1-w))
test.df

HTH,
Jorge


On Thu, Jan 6, 2011 at 8:33 AM, Vassilis <> wrote:

>
> Dear list,
>
> This must be an easy one. I have a data frame like this one:
>
> test.df <- data.frame(x1=c(2,3,5), x2=c(5, 3, 4), w=c(0.8, 0.3, 0.5))
>
> and I want to construct a weighted mean of the first two columns using the
> third column for weighting; i.e.
>
> y[1] = x1[1]*w[1] + x2[1]*(1-w[1])
> y[2] = ...
>
> One way to do this is to use a loop like
>
> test.df$y   <-numeric(3)
>
> with(test.df,
> for(i in 1:length(w)) {
> test.df$y[[i]]  <<- weighted.mean(c(x1[[i]],x2[[i]]),c(w[[i]],1-w[[i]]) ) }
> )
>
> My question is whether you can suggest a way to do the same without using a
> `for' loop, a vectorized version of this snippet - My actual dataset is
> large and it involves calculating the weighted mean of many columns. Such a
> loop becomes ugly to write and quite slow
>
> Thanks in advance,
>
> Vassilis
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/weighed-mean-of-a-data-frame-row-by-row-tp3177421p3177421.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Plotting colour-coded points

2011-01-05 Thread Jorge Ivan Velez
Hi Anjan,

Try something along the lines of

d$bb <- with(d, cut(b, c(0,9,19,29)))
with(d, plot(a, id, col = bb, pch = 16, las = 1))
legend('topright', as.character(levels(d$bb)), col = 1:length(levels(d$bb)),
ncol = 3, pch = 16)

where 'd' is your original data.frame.

HTH,
Jorge


On Wed, Jan 5, 2011 at 2:00 PM, ANJAN PURKAYASTHA <> wrote:

> Hi,
> I have a file of the following type:
>
> idab
> 1   0.5   5
> 2   0.7  15
> 3   1.6   7
> 40.5 25
> 
>
> I would like to plot the data in column a on the y-axis and the
> corresponding data in column id on the x-axis, so plot(a~id).  However I
> would like to colour these points according to the data in column b.
> column b data may be colour coded into the following bins: 0-9; 10-19;
> 20-29.
> Any idea on how to accomplish this?
> TIA,
> Anjan
>
> --
> ===
> anjan purkayastha, phd.
> research associate
> fas center for systems biology,
> harvard university
> 52 oxford street
> cambridge ma 02138
> phone-703.740.6939
> ===
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to 'explode' a matrix

2011-01-05 Thread Jorge Ivan Velez
Hi Kevin,

Take a look at

?kronecker

HTH,
Jorge


On Wed, Jan 5, 2011 at 7:03 AM, Kevin Ummel <> wrote:

> Hi everyone,
>
> I'm looking for a way to 'explode' a matrix like this:
>
> > matrix(1:4,2,2)
> [,1] [,2]
> [1,]13
> [2,]24
>
> into a matrix like this:
>
> > matrix(c(1,1,2,2,1,1,2,2,3,3,4,4,3,3,4,4),4,4)
> [,1] [,2] [,3] [,4]
> [1,]1133
> [2,]1133
> [3,]2244
> [4,]2244
>
> My current kludge is this:
>
> v1=rep(1:4,each=2,times=2)
> v2=v1[order(rep(1:2,each=4,times=2))]
> matrix(v2,4,4)
>
> But I'm hoping there's a more efficient solution that I'm not aware of.
>
> Many thanks,
> Kevin
>
> __
> 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] Saving objects inside a list

2011-01-03 Thread Jorge Ivan Velez
Hi Eduardo,

Try

r <- ls()
result <- sapply(r, get)
result

HTH,
Jorge


On Mon, Jan 3, 2011 at 12:25 PM, Eduardo de Oliveira Horta <> wrote:

> Hello there,
>
> any ideas on how to save all the objects on my workspace inside a list
> object?
>
> For example, say my workspace is as follows
> ls()
> [1] "x" "y" "z"
>
> and suppose I want to put these objects inside a list object, say
>
> object.list <- list()
>
> without having to explicitly write down their names as in
>
> object.list$x = x
> object.list$y = y
> object.list$z = z
>
> Is this possible?
>
> Thanks in advance,
>
> Eduardo Horta
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] subset question

2010-12-29 Thread Jorge Ivan Velez
Hi Anjan,

Try

subset(d, gene %in% c("i1", "i2", "i3"))

HTH,
Jorge


On Wed, Dec 29, 2010 at 4:55 PM, ANJAN PURKAYASTHA <> wrote:

> Hi,
> I'm having a problem with a step that should be pretty simple.
> I have a dataframe, d,  with column names : gene s1 s2 s3. The column
> "gene"
> stores an Id; the rest of the columns store intensity data.
> I would like to extract the rows for gene Ids i1, i2, i3 ( I know a priori
> that those rows exist).
> So I do this:
> subset(d, gene %in% c(i1, i2, i3)).
> This does not give me the required data.
> Any ideas where I am going wrong?
> TIA,
> Anjan
>
> --
> ===
> anjan purkayastha, phd.
> research associate
> fas center for systems biology,
> harvard university
> 52 oxford street
> cambridge ma 02138
> phone-703.740.6939
> ===
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Counting number of datasets and appending them

2010-12-29 Thread Jorge Ivan Velez
Hi Grace,

Try something along the lines of

do.call(rbind, lapply(1:maxi, function(x) get(paste('data', x, sep = ""

HTH,
Jorge


On Wed, Dec 29, 2010 at 5:06 PM, Li, Grace <> wrote:

> Hi there,
>
> I have a question on how to  read a bunch of dataset, assign each of the
> dataset to a matrix in the  memory, and append them.
>
> Suppose I have 20 dataset saved to different .rda files named
> gradeFileData1, gradeFileData2,, gradeFileData20. And I would like to
> read them each into a dataset in the memory, then combine them. I wrote
> something like:
>
> e1<-new.env(parent=.GlobalEnv)
> maxi <- 20
> i <- 1
> while (i<=maxi) {
> e1$d <-1
> datanam <- paste("data",i,sep="")
> data <- e1$d
> names(data)[length(data)] <- datanam
> i <- i+1
> }
>
> The function "names(data)[length(data)]" doesn't seem to work. I need it to
> be named like data1,data2,data20.
>
> Also to append them into a big dataset, I think there should be something
> simpler than
> all <-
> rbind(data1,data2,data3,data4,data5,data6,data7,data8.data20)
>
> can you help me on this? I hope this is not some simplest R question. I
> am a beginner.
>
> Thanks a ton!
>
> Grace
>
>
> Confidentiality Notice: This e-mail message including at...{{dropped:12}}
>
> __
> 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] Non-uniformly distributed plot

2010-12-23 Thread Jorge Ivan Velez
Hi Eric,

You can try

plot(x, y, log = 'xy')
fit <- lm(log(y)~log(x))
abline(fit, col = 2, lty = 2)
summary(fit)
par(mfrow = c(2,2))
plot(fit)

HTH,
Jorge


On Thu, Dec 23, 2010 at 5:55 PM, Eric Hu <> wrote:

> Thanks David. I am reposting the data here.
>
> Eric
>
>
> > Hi,
> >
> > I would like to plot a linear relationship between variable x and y.
> > Can anyone help me with scaled plotting and axes so that all data
> > points can be visualized somehow evenly? Plaint plot(x,y) will
> > generate condensed points near (0,0) due to several large data
> > points. Thank you.
> >
> > Eric
> >
> >
> > dput(x)
> c(0.349763, 3.39489, 1.52249, 0.269066, 0.107872, 0.0451689,
> 0.590268, 0.275755, 0.751845, 1.00599, 0.652409, 2.80664, 0.0269933,
> 0.137307, 0.282939, 1.23008, 0.436429, 0.0555626, 1.10624, 53,
> 1.30411, 1.29749, 53, 3.2552, 1.189, 2.23616, 1.13259, 0.505039,
> 1.05812, 1.18238, 0.500926, 1.0314, 0.733468, 3.13292, 1.26685,
> 3.10882, 1.01719, 0.13096, 0.0529692, 0.418408, 0.213299, 0.536631,
> 1.82336, 1.15287, 0.192519, 0.961295, 51, 0.470511, 4.05688,
> 1.78098, 0.364686, 1.24533)
> > dput(y)
> c(0.423279, 0.473681, 0.629478, 1.09712, 0.396239, 0.273577,
> 0.303214, 0.628386, 0.465841, 0.687251, 0.544569, 0.635805, 0.358983,
> 0.16519, 0.366217, 1.08421, 0.668939, 0.181861, 0.782656, 13.3816,
> 1.15256, 0.965943, 20, 2.86051, 0.304939, 1.94654, 0.967576,
> 0.647599, 0.520811, 1.27434, 0.363666, 0.93621, 0.544573, 0.696733,
> 1.0031, 3.78895, 0.694053, 0.289111, 0.178439, 0.746576, 0.391725,
> 0.363901, 1.20297, 0.461934, 0.364011, 0.691368, 20, 0.81947,
> 1.69594, 1.56381, 0.900398, 0.960948)
>
> __
> 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] regression

2010-12-22 Thread Jorge Ivan Velez
Hi Ufuk,

Using Michael's data, here is one more way of doing it:

allmodels <- lapply(1:nrow(x), function(row) with(x, lm(y ~ ., data =
x[-row,])))
allmodels

To access the information contained in the model when the first row is
removed, you can do

summary(allmodels[[1]])

And, if you want to have all coefficients, then

do.call(rbind, lapply(allmodels, coefficients))

is what you need.

HTH,
Jorge


On Wed, Dec 22, 2010 at 4:57 PM, ufuk beyaztas <> wrote:

>
> Hi dear all,
>
> suppose that s is a statistic code;
>
> i have a matrix (x) which has 7 columns (1=x1,2=x23=x3,4=x4,5=x5,6=x6
> and7=y)
> and has 20 rows. i want to do linear reggression like
> reg<-lm(x[,7]~1+x[,1]+x[,2]+...+x[,6])
> but i want to do delete i th row for nrows times and create regression
> model
> like above and compute each models'   "s" statistics and list them. but i
> could not do. i always get only one model and statistic.
> How can i do this
>
> Thanks any idea!
> --
> View this message in context:
> http://r.789695.n4.nabble.com/regression-tp3161328p3161328.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] vectorised recovery of strsplit value ??

2010-12-22 Thread Jorge Ivan Velez
Try

sapply(strsplit(sampleIDs, "_"), "[", 1)

HTH,
Jorge


On Wed, Dec 22, 2010 at 4:02 PM, maddox <> wrote:

>
> Dear Guru's
>
> My first steps with R have ground to a halt! I have a vector of sample
> identifiers
>
> > sampleIDs
>  [1] "D1_1"   "D1_2"   "D1_3"   "D1_4"   "D1_5"   "D1_6"   "D1_7"   "D1_8"
>  [9] "D1_9"   "D1_10"  "D1_11"  "D1_12"  "F1_13"  "F1_14"  "F1_15"  "F1_16"
> [17] "F1_17"  "F1_18"  "F1_19"  "F1_20"  "F1_21"  "F1_22"  "F1_23"  "F1_24"
> [25] "DDC_25" "DDC_26" "DDC_27" "DDC_28" "DDC_29" "DDC_30" "DDC_31"
> "DDC_32"
> [33] "DDC_33" "DDC_34" "DDC_35" "DDC_36"
>
> from which I've split the prefix identifier using strsplit
>
> > splitIDs <- strsplit( as.character(sampleIDs), "_")
> > splitIDs
> [[1]]
> [1] "D1" "1"
>
> [[2]]
> [1] "D1" "2"
>
> [[3]]
> [1] "D1" "3"
>
> [[4]]
> [1] "D1" "4"  etc
>
> I am now struggling to work with the prefix identifiers (D1, F1, DDC)
> because the only way I have figured out to access them is with
> splitIDs[[i]][1] i.e. it seems like I have to use a loop to get the
> identifiers into a factor and counted.
>
> Is there a vectorised solution someone can suggest?
> Or an alternative strategy .. these are early days using R for me!
> Thanks
>
>
> regards
>
> M
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/vectorised-recovery-of-strsplit-value-tp3161254p3161254.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] sample() issue

2010-12-20 Thread Jorge Ivan Velez
Hi Cory,

Check out
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

HTH,
Jorge


On Mon, Dec 20, 2010 at 2:04 PM, cory n <> wrote:

> > length(sample(25000, 25000*(1-.55)))
> [1] 11249
>
> > 25000*(1-.55)
> [1] 11250
>
> > length(sample(25000, 11250))
> [1] 11250
>
> > length(sample(25000, 25000*.45))
> [1] 11250
>
> So the question is, why do I get 11249 out of the first command and not
> 11250?  I can't figure this one out.
>
> Thanks
>
> Cory
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Time Series of Histograms

2010-12-19 Thread Jorge Ivan Velez
Hi Enrico,

Is this close to what you want to do?

http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109

HTH,
Jorge


On Sun, Dec 19, 2010 at 7:03 PM, Enrico R. Crema <> wrote:

> Dear List,
>
> I have a set of distributions recorded at an equal interval of time and I
> would like to plot them as series of horizontal histograms (with the x-axis
> representing time, and y-axis representing the bins) since the distribution
>  shifts from unimodal to multimodal in several occasions. What I would like
> to see is something close to a violinplot, but I do not want a kernel
> density estimate...
> Any suggestions or advice will be great!
>
> Thanks in Advance,
> Enrico
> __
> 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] check for item in vector

2010-12-13 Thread Jorge Ivan Velez
Hi CH,

Check

?is.element
?"%in%"

HTH,
Jorge


On Mon, Dec 13, 2010 at 9:48 AM, C.H. <> wrote:

> Dear R users,
>
> Suppose I have an vector like this:
>
> animal <- c("Tiger","Panda")
>
> I would like to know is there any function that check for the
> existence of certain item in a vector.
>
> e.g.
>
> > func("Tiger",animal) # check for the existence of "Tiger"
> TRUE
> > func("Acacia",animal)  #Acacia is not an item of the animal vector
> FALSE
>
> I know that it can be done by for loop. But I would like to know is
> there any built-in function for that.
>
> Thank you very much.
>
> CH
>
> --
> CH Chan
>
> __
> 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] break

2010-12-11 Thread Jorge Ivan Velez
If I understand correctly, the following should do it:

lag.max2 <- function(object, n = 12){
matris <- matrix(NA, nrow = n)
for(i in 1:n){
matris[i] <- ur.df(object, lags = i, type =
"trend")@testreg$coefficients[i+3,4]
   if(matris[i]<0.1) break
}
# output
 c('lag' = i, 'p' = matris[i])
   }
a2 <- lag.max2(a1)
a2
#   lag  p
# 1. 0.09613726

HTH,
Jorge


On Sat, Dec 11, 2010 at 3:17 PM, Serdar Akin <> wrote:

> Hi
>
> I'm trying to utilize the break command for breaking the loop when the
> p-value is less than 10 per cent using the urca package. But it does not
> break the loop, anyone that can help me?
>
> library(urca)
> set.seed(1)
> a1 <- runif(100)
> lag.max <- function(object, n = 12){
>matris <- matrix(NA, nrow = n)
>for(i in 1:n) {
>   matris[i] <- ur.df(object, lags = i,
>  type = "trend")@testreg$coefficients[i+3,4]
>   if (i <  0.1) {break(i)}
>   }
>   list(matris = round(matris, 3))
>   }
> a2 <- lag.max(a1)
>
> /With regards
> Serdar
>
>[[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] String to array

2010-12-09 Thread Jorge Ivan Velez
Try

f <- function(string) as.numeric(strsplit(string, "- ")[[1]])
f(x)
f(y)
f(z)

HTH,
Jorge


On Thu, Dec 9, 2010 at 9:24 AM, Romildo Martins <> wrote:

> Hello,
>
> how convert x in xarray (numbers)?
>
> > x
> [1] "0 - 13"
> > y
> [1] "11 - 23"
> > z
> [1] "220 - 9"
> > xarray
> [1]  0 13
> > yarray
> [1] 11 23
> > zarray
> [1] 220   9
>
>
>
> Thanks,
>
> RMB
>
> __
> 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.


  1   2   3   4   5   6   7   8   9   >