Re: [R] matrices call a function element-wise

2011-01-03 Thread Jonathan Christensen
Hi, I would recommend reformatting the data as a 2x2x1000 array and using apply. Jonathan On Mon, Jan 3, 2011 at 7:57 AM, zhaoxing731 wrote: > Hello > > I have 4 1000*1000 matrix A,B,C,D. I want to use the corresponding element of > the 4 matrices. Using the "for loop" as follow: > > E<-o > f

Re: [R] Converting data.frame from long to wide format

2010-12-08 Thread Jonathan Christensen
Matt, library(reshape2) wide.df <- dcast(df, y ~ x) Works great for me. Jonathan On Wed, Dec 8, 2010 at 7:26 PM, Matthew Pettis wrote: > Hi, > > I was wondering if there is an easy way that I am missing for turning a long > dataframe into a wide one.  Below is sample code that will make what

Re: [R] difference between linear model & scatterplot matrix

2010-12-03 Thread Jonathan Christensen
Francesco, My guess would be collinearity of the predictors. The linear model gives you the best fit to all of the predictors at once; unless the predictors are orthogonal (which in a case like this is certainly not the case), there is no guarantee that the parameter estimates which give the best

Re: [R] creating 'all' sum contrasts

2010-10-15 Thread Jonathan Christensen
Michael, Let c_1 and c_2 be vectors representing contrasts. Then c_1 and c_2 are orthogonal if and only if the inner product is 0. In your example, you have vectors (1,0,-1) and (0,1,-1). The inner product is 1, so they are not orthogonal. It's impossible to have more orthogonal contrasts than you

Re: [R] extract rows of a matrix

2010-10-12 Thread Jonathan Christensen
Hannah, a <- matrix(rnorm(1),nrow=500) new.matrix <- a[seq(0,dim(a)[1],by=20),] Jonathan On Tue, Oct 12, 2010 at 1:59 PM, li li wrote: > Hi all, >  I want to extract every 20th row of a big matrix, say 1 by 1000. > What is the simper way to do this? >   Thank you very much! >          

Re: [R] Combinations

2010-10-05 Thread Jonathan Christensen
Hi, On Tue, Oct 5, 2010 at 3:52 AM, Trying To learn again wrote: > > Hi all, > > Reading more I have find a partial solution on a part of the proble in some > part of the code it should appea something like: > > # NC: All the potential combinations 3^15 > > if > > NC[price(i,j)=="1" & price(i,j)=

Re: [R] Suppressing printing in the function

2010-10-01 Thread Jonathan Christensen
Dimitri, Maybe ?invisible will help? Jonathan On Fri, Oct 1, 2010 at 4:27 PM, Dimitri Liakhovitski < dimitri.liakhovit...@gmail.com> wrote: > Hello! > > I wrote a function that returns a data frame. Nowhere in the function > do I say print(my.data.frame), but when I run the function - the data

Re: [R] how to to if a calculation is out range?

2010-09-29 Thread Jonathan Christensen
Perhaps use lgamma? > lgamma(220) [1] 964.8206 Jonathan On Wed, Sep 29, 2010 at 3:22 PM, song song wrote: > for example, when I am calculating a posterior density, I need to calculate > gamma(75*3+5)=gamma(220) which is out of the bound of gamma function. what > shall I do for this condition>

Re: [R] next step in randomly sampling

2010-09-28 Thread Jonathan Christensen
Mike, Try growth[sample(1:length(growth)),] to permute the rows. Jonathan On Tue, Sep 28, 2010 at 8:38 PM, Michael Larkin wrote: > Thanks to the people on this list I was able to fix my code for randomly > sampling. Thanks. > > > > Now, I am moving on to the next step and I ran into another

Re: [R] need help with ramdomly sampling some data

2010-09-28 Thread Jonathan Christensen
Mike, It works for me: > data <- 1:8 > sample(data,replace=TRUE) [1] 6 4 5 2 5 8 7 2 Please provide a reproducible example, if possible, and the output of sessionInfo(). Jonathan On Tue, Sep 28, 2010 at 7:22 PM, Michael Larkin wrote: > I am trying to get R to randomly select values from my d

Re: [R] Plotting multiple animal tracks against Date/Time

2010-09-23 Thread Jonathan Christensen
Include individual as a factor in your dataset, and use ggplot2: library(ggplot2) ggplot(aes(x=Date, y=Distance, color=Individual), data=data) + geom_line() ought to do it. Jonathan On Thu, Sep 23, 2010 at 9:31 AM, Struve, Juliane wrote: > Sorry for posting this questions twice, but my previo

Re: [R] Setting scales for ggplot2 with facets

2010-09-11 Thread Jonathan Christensen
Swen, facet_grid forces the scale for plots along an axis to be shared. Try facet_wrap instead. Jonathan On Sat, Sep 11, 2010 at 2:21 PM, Sven Laur wrote: > Faceting in ggplot2 seems to permit different scales for different facets, > but I fail > to see how one could control ylim and xlim ran

Re: [R] How to run R on Emacs+ESS

2010-09-06 Thread Jonathan Christensen
Hi Stephen, Just to check: when you say you type "M-x R", are you typing the letter "M"? M-x in Emacs-speech means Meta-x, i.e., Alt-x. Jonathan On Mon, Sep 6, 2010 at 7:01 PM, Stephen Liu wrote: > Hi Dirk, > > Thanks for your advice. > > > Emacs and ESS already installed. > > $ apt-cache pol

Re: [R] ggplot2 multiple group barchart

2010-09-01 Thread Jonathan Christensen
Greg, Try this: library (ggplot2) v1 <- c(1,2,3,3,4) v2 <- c(4,3,1,1,9) v3 <- c(3,5,7,2,9) gender <- c("m","f","m","f","f") d.data <- data.frame (v1, v2, v3, gender) d.data #library(reshape) #library(plyr) # These are already loaded by ggplot2, but for your reference: reshape provides melt

Re: [R] Dealing with data

2010-08-14 Thread Jonathan Christensen
Your second fit makes no sense, as you can easily tell if you look at the regression summaries. Fitting with spray as a categorical variable gives you an overall p-value of less than 2.2e-16, while fitting with as.numeric(spray) gives an overall p-value of .2118. The fit you've done with as.numeric

Re: [R] Using R for Multiple Regression

2010-07-30 Thread Jonathan Christensen
Hi, Your X'X matrix is singular and there is not a unique solution. If you check, the regression equation which R gave you works just as well as yours. This is because your predictor variables are perfectly dependent. This will essentially never happen with real applications do to measurement erro

Re: [R] How to run this video link

2010-07-29 Thread Jonathan Christensen
R is a program for doing statistics, not for playing videos. I recommend you try something else. Jonathan On Thu, Jul 29, 2010 at 10:43 AM, Velappan Periasamy wrote: > Pls tell me how to run this video in R > > http://nptel.iitm.ac.in/video.php?courseId=1083&p=4 > >

Re: [R] how to code it??

2010-07-28 Thread Jonathan Christensen
On Wed, Jul 28, 2010 at 2:18 PM, Henrique Dallazuanna wrote: > You've tried: > > diff(c(0, x)) ? > This is clever, but not quite what he's asking for--it converts a sequence of 1's into a 1 followed by zeroes. Jonathan > > On Wed, Jul 28, 2010 at 3:10 PM, Raghu wrote: > > > Hi > > > > I have

Re: [R] error: arguments imply differing number

2010-07-28 Thread Jonathan Christensen
Hi, Thanks for including code and data so that we could reproduce what you're doing. Your problem is that you tell ddply to split the dataset by runNumber and cat1, which results in 4 groups. ddply then applies my.summary() to these four groups. One of these groups (cat1 = 1 and runNumber=1) has

Re: [R] Hydrology plots in R

2010-07-22 Thread Jonathan Christensen
Sam, I recommend taking a look at the ggplot2 package. This page from the author's website contains an example of what I think you are trying to achieve: http://had.co.nz/ggplot2/geom_segment.html Obviously, this would require doing the whole plot in ggplot2, but that's not at all unpleasant. Th

Re: [R] Historical Libor Rates

2010-07-19 Thread Jonathan Christensen
You might try asking on the R-SIG-Finance group, if nobody here can answer your question (https://stat.ethz.ch/mailman/listinfo/r-sig-finance). Jonathan On Mon, Jul 19, 2010 at 1:21 PM, Aaditya Nanduri wrote: > Hello All, > > Does anyone know how to download historical LIBOR rates of different

Re: [R] Storing processed results back into original objects

2010-07-15 Thread Jonathan Christensen
Steven, You can do it with assign() if you keep the names when you put the items in the list: Dlist <- list(D1=D1, D2=D2) # put the names of the objects in the list Newlist <- lapply(Dlist, function(x) x[, columns]) # create a new list with the output for(i in seq(length(Newlist))) { assign(na

Re: [R] write.csv() : attempt to set 'append' ignored... Why?

2010-07-15 Thread Jonathan Christensen
Never mind, I found the answer to my own question. From the 2.11.0 change log: owrite.csv[2] no longer allow 'append' to be changed: as ever, direct calls to write.table() give more flexibility as well as more room for error. Jonathan On Thu, Jul 15, 2010 at 2:01 PM

Re: [R] write.csv() : attempt to set 'append' ignored... Why?

2010-07-15 Thread Jonathan Christensen
Out of curiosity, is this a change in 2.11? I'm still runnning 2.10.1, ?write.csv mentions the other options being ignored, but not append. This might also explain why John Kane believes he has successfully used append with write.csv in that past. Jonathan On Thu, Jul 15, 2010 at 9:36 AM, Marc S

Re: [R] Need help on index for time series object

2010-07-13 Thread Jonathan Christensen
Megh, I don't know whether this is the best way, but it works: > seq(1,length(dat1))[!is.na(dat1)] [1] 1 2 4 5 6 9 10 Jonathan On Tue, Jul 13, 2010 at 1:58 PM, Megh Dal wrote: > Dear all, > > Please forgive me if there is a duplicate post; my previous mail perhaps > didnt reach the lis

Re: [R] left end or right end

2010-07-01 Thread Jonathan Christensen
Hi, You need to define what you want more exactly--what are the possible conclusions (hypotheses) you want to reach? Based on what you've said, I can think of several different approaches you might want, but I'm not sure which one of them you're actually after. For example: Hypothesis A: The dist

Re: [R] Embed function strips out date index

2010-06-30 Thread Jonathan Christensen
Manussawee, What type of object is series? We could help you better if we could reproduce exactly what you are trying to do, which requires more information (you made a good start by including data and code, though). The output of diff is a vector (time series, ...) with length one less than the

Re: [R] Why the variation when creating .pdf file output for my plots?

2010-06-30 Thread Jonathan Christensen
Karl, dev2bitmap runs its output through Ghostscript, and I assume that the difference is somehow due to that. I can't say whether Ghostscript is decreasing the file quality or just doing something clever, though. Jonathan On Wed, Jun 30, 2010 at 10:30 AM, Karl Brand wrote: > Thank you Erik!

Re: [R] ggplot qplot bar removing bars when truncating scale

2010-06-30 Thread Jonathan Christensen
Matthew, The ggplot documentation pages (http://had.co.nz/ggplot2) have the following to say under geom_bar: "A bar chart maps the height of the bar to a variable, and so the base of the bar must always been shown to produce a valid visual comparison." Thus, I suspect what you are trying to do m

Re: [R] Vertical subtraction in dataframes

2010-03-12 Thread Jonathan Christensen
Hello, On Fri, Mar 12, 2010 at 3:27 PM, Sam Albers wrote: > Hello all, > > I have not been able to find an answer to this problem. I feel like it > might > be so simple though that it might not get a response. > > Suppose I have a dataframe like the one I have copied below (minus the > 'calib' co

Re: [R] see the example and help me

2010-03-11 Thread Jonathan Christensen
Hi, On Thu, Mar 11, 2010 at 3:46 AM, chinna wrote: > > Hi Peter konings, > Sorry man the forecasted values i have given wrong > once again see my question and please give me the answer. > > > > This is the forecasted report that i get using the reporting tool cognos(BI > Reporting Too

Re: [R] axes limits in do3d

2010-02-23 Thread Jonathan Christensen
Hi, On Tue, Feb 23, 2010 at 4:03 AM, drlasher wrote: > > Does anybody know how to change the axes limits in do3d in made4? > > This is the code I have tried: > > do3d(sub, x=2, y=1, z=3, pch="+", > col="darkgreen", ylim=c(0,4), xlim=c(0,140) > ) > > But it doesn't seem to change the limits of t