[R] convert delimited strings with ranges to numeric

2013-08-14 Thread Chris Stubben
Is there an easy way to convert character strings with comma-separated numbers and ranges to a numeric vector? x- 2,5-7,10,12-15 [1] 2 5 6 7 10 12 13 14 15 Thanks, Chris -- Chris Stubben Los Alamos National Lab Bioscience Division MS M888 Los Alamos, NM 87545

Re: [R] [XML packages] how to get the sub-node according to the sub-node's attribute?

2013-07-12 Thread Chris Stubben
113 3.77 1.513 16.90 1 152 #OR? xpathSApply(doc, //record[@id='Lotus Europa']) getNodeSet(doc, //record[@id='Lotus Europa']) # And to list all Ids... xpathSApply(doc, //record, xmlGetAttr, id) [1] Mazda RX4 Mazda RX4 Wag Datsun 710 . -- Chris Stubben Los

Re: [R] rowspan and readHTMLTable

2013-05-08 Thread Chris Stubben
pcaA Rv0470cMycolic acid synthase (cyclopropane synthase) 4 Mycolic acid synthesis pcaA Rv0470cMycolic acid synthase (cyclopropane synthase) -- Chris Stubben Los Alamos National Lab Bioscience Division MS M888 Los Alamos, NM 87545

Re: [R] create unique ID for each group

2013-05-07 Thread Chris Stubben
I want to merge dat1 and dat2 based on ID in order Have you tried merge(dat1, dat2) ? If ID is the common column (and no others), then that should be all you need to join (see ?merge). And then order if needed. Chris -- Chris Stubben Los Alamos National Lab Bioscience Division MS M888

Re: [R] recode categorial vars into binary data

2013-05-07 Thread Chris Stubben
=TRUE)) Chris -- Chris Stubben Los Alamos National Lab Bioscience Division MS M888 Los Alamos, NM 87545 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R

Re: [R] create unique ID for each group

2013-05-07 Thread Chris Stubben
in raw datasets are pretty important, especially if observations are split into different files and you are trying to join them later. How do you know for ID 0001 and obs 1 that height is 3.2 and not 2.6, especially if order in the two files are not exactly the same. Chris -- Chris Stubben

[R] rowspan and readHTMLTable

2013-05-06 Thread Chris Stubben
. t1 - readHTMLTable( http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3544749/table/T1;, which=1) Thanks, Chris t1-readHTMLTable( http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3544749/table/T1;, which=1) -- Chris Stubben Los Alamos National Lab Bioscience Division MS M888 Los Alamos, NM

Re: [R] Remove superscripts from HTML objects

2012-04-13 Thread Chris Stubben
Sorry if I was not clear. I wanted to remove the superscripts using xpath queries if possible. For example this will get p nodes with superscripts, but how do I remove the superscripts if there are many matching nodes and different superscripts? xpathSApply(doc, //p[sup], xmlValue) [1] Cata

Re: [R] Getting codebook data into R

2012-02-13 Thread Chris Stubben
8 642 1 33016 8874.441 9 71 1 7 939 1 12808 6911.880 10 71 2 6 1035 1 23233 6911.880 Chris Stubben Daniel Nordlund-4

Re: [R] Markov transition matrices , missing transitions for certain years

2011-04-19 Thread Chris Stubben
To keep the table dimensions the same, try changing the columns to factors... boxes$y97-factor(boxes$y97, 1:4) boxes$y98-factor(boxes$y98, 1:4) boxes$y99-factor(boxes$y99, 1:4) ... table(boxes$y98, boxes$y97) 1 2 3 4 1 1 0 1 0 2 0 0 0 0 3 0 0 0 0 4 1 0 0 1 table(boxes$y99,

Re: [R] rotate column names in large matrix

2010-11-16 Thread Chris Stubben
Just increase the margins on the left side and add the rownames x - cor(matrix(rnorm(600), 60, 100)) rownames(x)-paste(row, 1:100) op-par(mar=c(1,5,1,1), xpd=TRUE) image(t(x[nrow(x):1,]), axes=FALSE) text(-0.01, seq(0,1,length=nrow(x) ), rownames(x), pos = 2, offset = 0, cex = .7) Another

Re: [R] rotate column names in large matrix

2010-11-15 Thread Chris Stubben
degree counter clockwise rotation image(t(x[nrow(x):1,]), axes=FALSE) ## add 100 column names y-paste(column, 1:100) text( seq(0,1,length=100) , 1.01, y, pos = 2, srt = 270, offset=0, cex=.7) Chris Stubben Lara Poplarski wrote: I have a large (1600*1600) matrix generated with symnum, that I

Re: [R] R eat my data

2010-05-25 Thread Chris Stubben
Gene names often have single quotes like 5'-methylthioadenosine phosphorylase ATP synthase B' chain ppGpp 3'-pyrophosphohydrolase so maybe try adding quote= to the read table options. Chris Stubben -- View this message in context: http://r.789695.n4.nabble.com/R-eat-my-data

[R] Using substitute in a print method

2010-03-19 Thread Chris Stubben
Thanks for any help, Chris Stubben -- View this message in context: http://n4.nabble.com/Using-substitute-in-a-print-method-tp1606635p1606635.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https

Re: [R] popbio and stochastic lambda calculation

2010-02-18 Thread Chris Stubben
Shawn Morrison-2 wrote: # The paper reports a 95% CI of 0.79 - 1.10 # My reproduced result for the CIs is much larger, especially on the upper end. Why would this be? # The authors report using the 'delta' method (Caswell, 2001) to calculate the CI in which the Shawn, I probably

Re: [R] splitting scientific names into genus, species, and subspecies

2009-11-04 Thread Chris Stubben
Mark W. Miller wrote: I have a list of scientific names in a data set. I would like to split the names into genus, species and subspecies. Not all names include a subspecies. Could someone show me how to do this? strsplit should work for your example... data.frame(

Re: [R] Matrix multiplication and random numbers

2009-09-09 Thread Chris Stubben
,]0 0. 0. 0. 96.92715 0.00.0 108.6551 [6,]0 0. 0. 0. 0.0 69.875270.0 0. [7,]0 0. 0. 0. 0.0 0.0 65.86229 0. Chris Stubben -- View this message in context: http

Re: [R] Stochastic (transition) matrices: how to determine distributions and variance?

2009-08-31 Thread Chris Stubben
) y1-y[z,] n2[i,] -prop.table( table(y1[,2], y1[,1]), 2) %*% n } # the CIs are much wider here apply(n2, 2, quantile, c(0.025,0.975)) [,1] [,2] [,3] 2.5% 55.89959 132.6868 361.2091 97.5% 85.11097 169.3798 399.7032 Chris Stubben -- View this message in context: http

[R] Long character not truncated by str() after adding comment

2009-07-22 Thread Chris Stubben
(longch) # not truncated Thanks, Chris Stubben -- View this message in context: http://www.nabble.com/Long-character-not-truncated-by-str%28%29-after-adding-comment-tp24611767p24611767.html Sent from the R help mailing list archive at Nabble.com. __ R

Re: [R] sampling quadrats of increasing size in a list of matrices

2009-06-30 Thread Chris Stubben
, then maybe combine the code above into a function and then apply it to your list using lapply. Chris Stubben -- View this message in context: http://www.nabble.com/sampling-quadrats-of-increasing-size-in-a-list-of-matrices-tp24270434p24276950.html Sent from the R help mailing list archive

Re: [R] how to calculate means of matrix elements

2009-05-18 Thread Chris Stubben
dimensions) mat - matrix(unlist(x), n * p, length(x)) mm - matrix(rowMeans(mat, ...), n, p) dimnames(mm) - dimnames(x[[1]]) mm } Chris Stubben -- View this message in context: http://www.nabble.com/how-to-calculate-means-of-matrix-elements-tp23607694p23609472.html Sent from the R help

Re: [R] Looking for a quick way to combine rows in a matrix

2009-05-13 Thread Chris Stubben
21 29 AT 2 6 10 14 TA 3 7 11 15 Chris Stubben jholtman wrote: Try this: key - rownames(a) key[key == AT] - TA do.call(rbind, by(a, key, colSums)) V2 V3 V4 V5 AA 1 5 9 13 TA 5 13 21 29 TT 4 8 12 16 On Mon, May 11, 2009 at 4:53 PM, Crosby, Jacy R jacy.r.cro

Re: [R] Download daily weather data

2009-02-27 Thread Chris Stubben
-- Chc -- -- -- 6 42 42 35 14 W 100 35 100 -- Chc -- -- -- # plot plot(z[Temp]) Chris Stubben -- View this message in context: http://www.nabble.com/Download-daily-weather-data-tp22233373p22252517.html Sent from the R help mailing list archive

[R] how to save an updated dataset

2008-06-11 Thread Chris Stubben
, if the user has permission to save to that directory, and probably some other complications I'm missing. Any suggestions? Thanks, Chris Stubben -- View this message in context: http://www.nabble.com/how-to-save-an-updated-dataset-tp17782584p17782584.html Sent from the R help mailing list archive

Re: [R] SQL INSERT using RMySQL

2008-04-11 Thread Chris Stubben
Greg, If you have a MySQL table with an auto_increment field, you could just insert a NULL value into that column and the database will increment the key (it may not work in SQL STRICT mode, I'm not sure). I don't think there's any way to specify which columns you want to load data into using

Re: [R] projection.matrix() {popbio} for more than one matrix

2008-02-24 Thread Chris Stubben
Michelle, I would probably run a loop as well and save all matrices to a single list (see hudsonia and calathea on working with lists of matrices). First, run the example(test.census) to get the stage-fate data frame trans and then run this code to save the matrices into a list all.

Re: [R] Population model question

2008-01-15 Thread Chris Stubben
-Halcyon- wrote: My question is : How do I arbitrarily assign the animals being FALSE ***according to the uniformal chance generation*** to the array Dead.Animals, there being TRUE? Maybe I'm missing something, but aren't dead animals just the ones that aren't alive? Why do you even

Re: [R] stochastic growth rate (package popbio)

2008-01-14 Thread Chris Stubben
privalan wrote: However, I cannot figure out the way to compute the asymptotic stochastic population growth rate using “popbio”. I would like to perform a stochastic model in which my demographic rates are sampled from beta distribution with known mean and SD. For example, rather than 0.50

Re: [R] Diagonal matrix with off diagonal elements

2007-12-21 Thread Chris Stubben
Also try the odiag function in the demogR package odiag( 1:5, -1) [,1] [,2] [,3] [,4] [,5] [,6] [1,]000000 [2,]100000 [3,]020000 [4,]003000 [5,]000400 [6,]000

Re: [R] Inserting a subsequence between values of a vector

2007-12-04 Thread Chris Stubben
You could use a combination of rle, cumsum and append. x - c(1,1,1,2,2,3,3,3,3,3,4) y-rle(x)$lengths y [1] 3 2 5 1 z-cumsum(y)[y1] z [1] 3 5 10 for(i in rev(z)) x - append(x, c(0,0,0), after = i) x [1] 1 1 1 0 0 0 2 2 0 0 0 3 3 3 3 3 0 0 0 4 Chris Serguei Kaniovski-3 wrote:

Re: [R] Generating these matrices going backwards

2007-11-15 Thread Chris Stubben
Sorry, I wasn't sure what you meant. This way will return more than one answer, right? N-c(1,2,1,3) R-c(1.75,3.5,1.75,1.3125) ## get all 126 combinations of five 0's and four 1's for matrix cbn-as.matrix(expand.grid( rep( list(0:1), 9))) cbn- cbn[rowSums(cbn)==4,] ans-list() ctr-0 ## loop

[R] reading tables from url

2007-11-14 Thread stubben
that I missed in the documentation/help. Chris -- --- Chris Stubben Los Alamos National Lab BioScience Division MS M888 Los Alamos, NM 87545 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] Generating these matrices going backwards

2007-11-14 Thread Chris Stubben
Maybe something like this? N-c(1,2,1,3) ## create empty matrix x-diag(0,3) ## fill off diagonal x[row(x)==col(x)+1]-N[1:2] # fill 3rd column x[1:2,3]-N[3:4] Or create a function and return both x and y mat3-function(N) { x-diag(0,3) # fill each element separately x[2,1]-N[1] x[3,2]-N[2]

Re: [R] Elasticity in Leslie Matrix

2007-10-29 Thread Chris Stubben
Sorry, I didn't think carefully about your question on my first reply, so please ignore it. Chapter 9 in Morris and Doak (2002) cover vital rate elasticities and sensitivities (see Box 9.1 for Matlab code http://www.sinauer.com/PVA/vitalsens.m). Simon, thanks for posting your code, I will

Re: [R] Elasticity in Leslie Matrix

2007-10-22 Thread Chris Stubben
I would like to calculate elasticities and sensitivities of each parameters involved in the following transition matrix: A - matrix(c( sigma*s0*f1, sigma*s0*f2, s, v ), nrow=2, byrow=TRUE,dimnames=list(stage,stage)) The command eigen.analysis avaliable in

Re: [R] collapsing a data frame

2007-10-12 Thread Chris Stubben
On 10/12/07, Ben Bolker bolker at ufl.edu wrote: Trying to find a quick/slick/easily interpretable way to collapse a data set. Another alternative for SQL fans is the sqldf package. I used the MySQL driver here since SQLite does not support standard deviation. sqldf(select BROOD,

Re: [R] RMySQL NA/NULL value storage error

2007-09-28 Thread Chris Stubben
Adam Wilson-4 wrote: I am running R 2.5.1, RMySQL 0.6 , and DBI 0.2-3 on Windows XP Like others, I am having trouble with NA/Null value conversions between R and a MySQL database via DBI, but I could not find my exact problem in the archives. Most of the time NA values in R get

Re: [R] 3d barplot in rgl

2007-09-26 Thread Chris Stubben
Transition matrices are Markov transition matrices among different life stages of organisms -- in the simplest case (Leslie matrices, Ben, Thanks for your clear explanation and plot examples. I like the dotplots alot and added a few modifications below. Since I often compare rows and

[R] 3d barplot in rgl

2007-09-25 Thread stubben
] A-matrix(c( 0.21, 0.21,0.03, 0.55, 0.58, 0.09, 1.30, 1.35, 0.22), nrow=3, byrow=TRUE, dimnames=list(stages,stages) ) ## I can get a surface plot, but that's about it. persp3d(A, col=red, alpha=0.7, xlab=fate, ylab=stage, zlab=Sensitivity, box=FALSE) Thanks, Chris Stubben

Re: [R] 3d barplot in rgl

2007-09-25 Thread Chris Stubben
hadley wickham h.wickham at gmail.com writes: Why do you want a 3d barchart? They are generally a bad way to present information as tall bars can obscure short bars, and it is hard to accurately read off the height of a bar. While adding rotation can reduce some of these problems, why not

Re: [R] 3d barplot in rgl

2007-09-25 Thread Chris Stubben
Duncan Murdoch murdoch at stats.uwo.ca writes: That demo gives you the basics of the code, so it shouldn't be too hard to put your own together: just strip out the counting part. Thanks, I did download the source to check the hist3d demo, but honestly it didn't look very easy to