Re: [R] creating a reverse geometric sequence

2010-05-23 Thread Dan Davison
Erik Iverson writes: > Hello, > > Can anyone think of a non-iterative way to generate a decreasing > geometric sequence in R? > > For example, for a hypothetical function dg, I would like: > >> dg(20) > [1] 20 10 5 2 1 > > where I am using integer division by 2 to get each subsequent value in > t

Re: [R] C function call in R

2010-05-18 Thread Dan Davison
John Lande writes: > dear all, > > we am trying to improve the performance of my R code, with the implentation > of some function with custom C code. > we found difficult to import and export/import data structure such us > matrices or data.frame into the external C functions. Please give a *ver

Re: [R] applying quantile to a list using values of another object as probs

2010-05-17 Thread Dan Davison
"Lorenzo Cattarino" writes: > Hi Jim, > > Thanks for your reply. Your codes does work but I was hoping to find a > way to use lapply and avoid the for loop. > > Lorenzo > > > -Original Message- > From: Jim Lemon [mailto:j...@bitwrit.com.au] > Sent: Monday, 17 May 2010 8:27 PM > To: Loren

Re: [R] Variable variables using R ... e.g., looping over data frames with a numeric separator

2010-05-17 Thread Dan Davison
Monte Shaffer writes: > Hello, > > I have programmed in PHP a lot, and wanted to know if anyone figured out > Variable variables using R. > > For example, I have several dataframes of unequal sizes that relate to L > treatments (1, 2, 3, 4, 5,6, L) ... in this case L=7 You should create a list c

Re: [R] reading in all files of a certain type

2010-05-17 Thread Dan Davison
jim holtman writes: > try: > > pattern="*result*\\.csv$" Just for the record, that's not quite correct. The * doesn't behave like in a shell glob. Instead, * says "0 or more copies of the previous character". So the above pattern picks up resul.csv, which I don't think was intended. I don't kno

Re: [R] reading in all files of a certain type

2010-05-17 Thread Dan Davison
Dimitri Liakhovitski writes: > Thanks again - and one follow-up question. > When I do do.call(rbind, lapply(dir(patt = "\\.csv$"), read.csv)) > What is the right way to speicify (probably under "patt") that I only > need to grab those .csv files that contain a certain string, e.g., > "result"? I

[R] Using dev.copy

2010-03-22 Thread Dan Davison
I'm working over an ssh connection without X11 graphics. I'm making a plot, the first stage of drawing which takes a long time. I want to experiment with adding details. Here is what I was hoping to do, which results in error. ## Draw the master plot on png dev 2 png(file="master.png") plot(1:10)

Re: [R] lapply to apply a function using a vector

2010-02-17 Thread Dan Davison
Flana gmail.com> writes: > > Hi, > > First, thank you all for your help. > > Here is my problem (simplified): > > Say I have a list: > a=list(matrix(50,nrow=5,ncol=5), > matrix(25,nrow=5,ncol=5), > matrix(10,nrow=5,ncol=5)) > > I'd like to use rbinom with a different probability for each m

Re: [R] NMDS ordination

2010-02-13 Thread Dan Davison
Aisyah ioz.ac.uk> writes: > > > Hi > > Im currently trying to plot my NMDS data together with fitted variables > (envfit funct) on an ordination plot. The plot function shows two > displays="sites" and "sp". I was wondering how to plot it so that the sites > come up as different points for dif

Re: [R] how to do calculations in data matrices?

2010-02-13 Thread Dan Davison
Zoppoli, Gabriele (NIH/NCI) [G] mail.nih.gov> writes: > > Please give me just a reference where I can find something useful. The others are right that rather than randomly googling, you should bite the bullet and sit down for a couple of hours with some introductory material on R (a book, or o

Re: [R] Code working but too slow, any idea for how to speed it up ?(no loop in it)

2010-02-12 Thread Dan Davison
anna hotmail.com> writes: > > Hello my friends, > here is a code I wrote with no loops on matrix that is taking too long (2 > seconds and I call him 720 times --> 12 minutes): > > mat1 and mat2 are both matrix with 103 columns and 164 rows. Could you provide some example code creating matrice

Re: [R] paired wilcox test on each row of a large dataframe

2010-02-12 Thread Dan Davison
gauravbhatti hotmail.com> writes: > > > hI > I have to calculate V statistic for each row of a large dataframe > (28000). I can not use multtest package for paired wilcox test. I have > been using for loop which are. Is there a way to speed the computation > with another method like using appl

Re: [R] List to matrix or to vectors conversion

2010-02-12 Thread Dan davison
manchester.ac.uk> writes: > > On 12-Feb-10 13:14:29, Juan Tomas Sayago wrote: > > Dear list, > > I have a list with 1000 x1000 lines and columns Lists have neither lines nor columns. Can you explain exactly what you have? E.g. show us the code that created your "list"? > do you know how I can

Re: [R] Access variables by string

2010-02-11 Thread Dan davison
Philipp Rappold gmail.com> writes: > > Dear all, > [...] > (2) I need this functionality for a customized na.exclude() function > that I am building, which should only exclude rows that have NA in > certain columns. Maybe there is already a function which does > exactly what I need, so I'd h

Re: [R] matching matrix columns to a vector

2008-11-24 Thread Dan Davison
Dan Davison wrote: > > > > Jagat.K.Sheth wrote: >> >> How about which(colSums(t-v) == 0) ? >> > > But what about v=c(2,1,3)? It needs to be something like > > which(colSums((t - v)^2)) == 0 > or > which(colSums(abs(t - v))) == 0 >

Re: [R] matching matrix columns to a vector

2008-11-24 Thread Dan Davison
Jagat.K.Sheth wrote: > > How about which(colSums(t-v) == 0) ? > But what about v=c(2,1,3)? It needs to be something like which(colSums((t - v)^2)) == 0 or which(colSums(abs(t - v))) == 0 Dan Jagat.K.Sheth wrote: > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROT

Re: [R] Is there a way to not use an explicit loop?

2008-09-17 Thread Dan Davison
Both shape parameters of rbeta can be vectors; for x <- rbeta(n, shape1, shape2) x[i] ~ Beta(shape1[i], shape2[i]) so bbsim <- function(m=1000, num.post.draws=1e4, size.a=100, prob.a=.27, prior.count=1) { data.count <- rbinom(m, size.a, prob.a) shape1 <- rep(prior.count + data.count, e

Re: [R] Unexpected returned value from a function

2008-09-16 Thread Dan Davison
What you want is ConvertMissingToNA <- function (values) { values[ values == - | values == -99] <- NA return( values ) } To see why your version doesn't do what you wanted, maybe it helps to consider the following? x <- 1:10 y <- (x[3:6] <- 99) y ## 99 (It's perhaps not entirely o

Re: [R] Spatial join ? optimizing code

2008-09-16 Thread Dan Davison
Hi Monica, I think the key to speeding this up is, for every point in 'track', to compute the distance to all points in 'classif' 'simultaneously', using vectorized calculations. Here's my function. On my laptop it's about 160 times faster than the original for the case I looked at (10,000 observa

Re: [R] Scripting in R -- pattern matching, logic, system calls, the works!

2008-09-16 Thread Dan Davison
Instead of writing some long, ugly, "script", the way to use R is to break problems down into distinct tasks. Reading data is one task, and performing regressions on the data, plotting & summarising are different tasks. Write functions to do each task in general, and then use those functions. So o

Re: [R] Very confused with class

2008-08-22 Thread Dan Davison
Hi Rich, Richard M. Heiberger wrote: > > Dan, > > The real problem is the use of csv files. csv files don't handle missing > values > ("#VALUE" is most likely from Excel), dates, or other complications very > well. > > Read your Excel file directly into > R with one of the packages designed

Re: [R] Very confused with class

2008-08-21 Thread Dan Davison
helping matters. I don't even > understand why R is interpreting these figures as factors in the first > place, doesn't this imply that any similar data would be interpreted as > factors? > Thanks for any further help. > Robin Williams > Met Office summer intern - He

Re: [R] Very confused with class

2008-08-21 Thread Dan Davison
Hi Robin, You haven't said where you're getting the data from. But if the answer is that you're using read.table, read.csv or similar to read the data into R, then I advise you to go back to that stage and get it right from the outset. It's very, very common to see people who are relatively new to

Re: [R] [help] simulation of a simple Marcov Stochastic process for population genetics

2008-08-21 Thread Dan Davison
On Thu, Aug 21, 2008 at 03:00:51AM -0700, z3mao wrote: > > Hi, this is my first time using R. I want to simulate the following process: > "in a population of size N, there are i individuals bearing genotype A, the > number of those bearing A is j in the next generation, which following a > binomin

Re: [R] dynamically extract data from a list

2008-08-12 Thread Dan Davison
Dries Knapen-2 wrote: > > Hi, > > Thanks for your reply. However, this didn't work exactly as I needed > it to since the expression is dynamically built as a character vector > > i.e. not executed as > e <- expression(Sepal.Width > 4) > > but as > e <- expression("Sepal.Width > 4") > > in

Re: [R] Between the values

2008-08-12 Thread Dan Davison
o in those softwares? R is not trying to be a competitor to them; they do lots of things R doesn't, and vice versa. Dan Shubha Vishwanath Karanth wrote: > > > Thanks, Shubha > > > -Original Message- > From: Dan Davison [mailto:[EMAIL PROTECTED] >

Re: [R] Between the values

2008-08-12 Thread Dan Davison
On Tue, Aug 12, 2008 at 05:16:01PM +0530, Shubha Vishwanath Karanth wrote: > Hi R, > > > > This is a very trivial one > > > > C=0.1 > > > > I want to check whether my value of C is between 0 and 1 exclusively > I don't want to use (C>0 & C<1). And I can't use a single statement

Re: [R] Frequency vector

2008-08-12 Thread Dan Davison
On Tue, Aug 12, 2008 at 01:21:29AM -0700, dennis11 wrote: > > I want to create a vecor with frequencies. > > I have tried this: > > a <- c(1,1,1,1,2,3,4,5,5) > b <- table(a) > print (b[1]) > > which results in: > > print (b[1]) > 1 > 4 > > The only thing I want is the 4. > > So this seems

Re: [R] Quickly calculating the mean results over a collection of data sets?

2008-08-12 Thread Dan Davison
On Tue, Aug 12, 2008 at 04:47:14AM -0400, Michael R. Head wrote: > I have a collection of datasets in separate data frames which have 3 > independent test parameters (w, x, y) and one dependent variable (z) , > together with some additional static test data on each row. What I want > is a data fram

Re: [R] using IF command

2008-08-10 Thread Dan Davison
On Mon, Aug 11, 2008 at 08:23:19AM +1200, Gareth Campbell wrote: > Hey team, > > If I have a matrix: > > 1, 2, > 3, 4, > 4, 0, > 1, 3, > 0, 3 > > 2 columns. > > I want to write an if command that looks at (in this case) row 3 and looks > to see if either [3,1] or [3,2] has a zero in it. IF it

Re: [R] help using outer function

2008-08-10 Thread Dan Davison
On Sun, Aug 10, 2008 at 06:00:21PM +0100, Dan Davison wrote: > On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote: > > > > Hi, > > I would like to use the R's outer function on y below so that I can subtract > > elements from each other. The resulting data

Re: [R] help using outer function

2008-08-10 Thread Dan Davison
On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote: > > Hi, > I would like to use the R's outer function on y below so that I can subtract > elements from each other. The resulting dataframe is symmetric, save for the ^^ outer() returns a matri

Re: [R] Converting nested "for" loops to an "apply" function(s)

2008-08-10 Thread Dan Davison
On Sat, Aug 09, 2008 at 08:53:00PM -0400, Kurt Newman wrote: > > Resending. Previous message was truncated. Sorry for possible confusion. > > > > From: [EMAIL PROTECTED] > > To: r-help@r-project.org > > Date: Sat, 9 Aug 2008 18:25:47 -0400 > > Subject: [

Re: [R] Scripting - query

2008-08-10 Thread Dan Davison
On Sun, Aug 10, 2008 at 02:44:00PM +1200, Gareth Campbell wrote: > I have a vector: > alleles.present<-c("D3", "D16", ... ) > > The alleles present changes given the case I'm dealing with - i.e. either > all of the alleles I use for my calculations are present, or some of them. > > Depending on w

Re: [R] effective matrix subset

2008-08-09 Thread Dan Davison
On Sat, Aug 09, 2008 at 06:29:59AM -0500, Marc Schwartz wrote: > on 08/09/2008 06:01 AM [EMAIL PROTECTED] wrote: >> Hi; >> If we have a matrix A, and a vector X, where length(X)=nrow(A), and X >> contains a wanted column for each row in A, in row ascending order. How >> would be the most effective

Re: [R] read.table question

2008-08-09 Thread Dan Davison
On Fri, Aug 08, 2008 at 07:27:13PM -0700, Alessandro wrote: > Hi All. > > > > I have a file txt with 3 columns (X, Y and Z). every rows has 4 decimal > place (i.e. x.). I use read.table to import the data in R, but with > summary(), I don't see the decimal place after the dot. Is there any

Re: [R] import/export txt file

2008-08-09 Thread Dan Davison
On Fri, Aug 08, 2008 at 04:44:13PM -0700, Alessandro wrote: > Hi All, > > > > I have 2 questions: > > 1. Import: when I import my txt file (X,Y and Z) in R with "testground > <- read.table(file="c:/work_LIDAR_USA/R_kriging/ground26841492694149.txt", > header=T)", I lost the 4 number afte

Re: [R] Creating an array of lists

2008-08-07 Thread Dan Davison
Gang Chen-4 wrote: > > Hi, > > I want to store some number of outputs from running a bunch of > analyses such as lm() into an array. I know how to do this with a > one-dimensional array (vector) by creating > > myArray <- vector(mode='list', length=10) > Note that in R terminology, 'myArray'

Re: [R] List of "occurrence" matrices

2008-08-07 Thread Dan Davison
Lauri Nikkinen wrote: > > R users, > > I don't know if I can make myself clear but I'll give it a try. I have > a data.frame like this > > x <- "var1,var2,var3,var4 > a,b,b,a > b,b,c,b > c,a,a,a > a,b,c,c > b,a,c,a > c,c,b,b > a,c,a,b > b,c,a,c > c,a,b,c" > DF <- read.table(textConnection(x),

Re: [R] Union of columns of two matrices

2008-08-07 Thread Dan Davison
On Wed, Aug 06, 2008 at 06:32:43PM -0400, Giuseppe Paleologo wrote: > I was posed the following problem/teaser: > > given two matrices, come up with an "elegant" (=fast & short) function that > returns a matrix with all and only the non-duplicated columns of both > matrices; the column order does

Re: [R] Index alternative to nasty FOR loop?

2008-08-07 Thread Dan Davison
On Wed, Aug 06, 2008 at 05:42:21PM +, zack holden wrote: > > Dear R wizards, > > I have a folder containing 1000 files. For each file, I need to extract the > first row of each file, paste it to a new file, then write out that file. > Then I need to repeat this operation for each additiona

Re: [R] subsetting with column name as string

2008-08-06 Thread Dan Davison
On Wed, Aug 06, 2008 at 11:53:25AM -0400, Faheem Mitha wrote: > > Hi, > > Consider the following > >> x = c(1,2) >> y = c(3,4) >> d = data.frame(cbind(x,y)) >> d$x > [1] 1 2 >> d$"x" > [1] 1 2 >> >> foo = function(val) > + { > + return(d$val) > + } >> >> bar = function() > + { > + return(d$"x")

Re: [R] Font size in plots (I do NOT understand par help)

2008-08-06 Thread Dan Davison
On Wed, Aug 06, 2008 at 03:37:48PM +0100, Stephane Bourgeois wrote: > Hi, > > > > I do not get how par works, help please. > > > > Let's say I have a simple plot: plot(1:10) > > > > I want to change the font size for the x axis... how do I do that? OK, so firstly go to the help page f