Re: [R] Two conditions selection

2015-08-04 Thread Pete Brecknock
Rodrigo Díaz wrote Hi. I have a matrix like this: cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))col=c(rep(blue,2),rep(green,2),rep(blue,2),rep(green,2),rep(blue,2),rep(green,2))values=c(1:12)data.frame(cycle,col,values) # cycle col values#1 1 blue 1#2 1 blue 2#3 1

Re: [R] sapply function and poisson distribution

2015-01-04 Thread Pete Brecknock
dimnik wrote thank you for your answer.Yes,that sounds right.I thought the same thing but the problem is how can i generalize the command for every vector of numbers not only for the specific example?not only for c(1,2),c(0.1,0.8). 2015-01-04 0:45 GMT+00:00 Pete Brecknock [via R] ml-node

Re: [R] sapply function and poisson distribution

2015-01-03 Thread Pete Brecknock
dimnik wrote i want to find a functionthattakes in two vectors of numbers thathave the same length.The output should be a listof vectors, where each vector is a sequence of randomly generated Poisson variableswhere the

Re: [R] Selecting a maximum value in same ID

2014-03-08 Thread Pete Brecknock
Lee wrote Hi, I am struggling with this issue and need some helps. The data set 'DF' includes persons' IDs and other variables A, B, and C. Each Person has multiple values in A, B, and C. What I am trying to do is 1) selecting a maximum value of B within same ID, and 2) making a new data

Re: [R] multiple plots

2014-03-08 Thread Pete Brecknock
slavia wrote Hi, I have some values that I need to represente in the same plot. For exemple, if I have, c-c(200,205,210,215,220,225,230,235) a-c(0.032,0.44,0.86,0.65,0.53,0.213,0.46,0.231) b-c(0.325,0.657,0.784,0.236,0.798,0.287,0,748,0.785)

Re: [R] Lattice Barchart

2014-02-16 Thread Pete Brecknock
Pete Brecknock wrote Hi The code below plots a stacked barchart. I would like to overlay on this chart a circular plotting character at the sum of the bars for each month. The plotted characters should be joined with a line. So, for 1/1/2014, I would like to see a point at 200 (-1000

Re: [R] Dataset to single column matrix

2014-01-07 Thread Pete Brecknock
Krishia wrote Hello, I am pretty new to R and would like to transform my 272x12 matrix into a 3264X1. I'm trying to have the setup change from: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 13,14,15,16,17,18,19,20,21,22, 23, 24 etc. to 1 2 3 4 5 6 7 8 9 10 11 12 etc. Any

Re: [R] midpoint between two dates

2013-11-17 Thread Pete Brecknock
eric wrote Is there an easy way to get the midpoint between two dates in a data frame ? If I have a dataframe that looks like this : head(x) instDay remDay exp.time mpy 1 2006-02-02 2006-04-03 60 0.2 2 2006-04-17 2006-08-17 122 0.3 4 2006-08-17 2006-10-23 67

Re: [R] plot time series data in wide format

2013-11-01 Thread Pete Brecknock
wudadan wrote Dear R users, I wonder if there is a way that I can plot a time series data which is in a wide format like this: CITY_NAME 2000Q12000Q2 2000Q32000Q4 2001Q1 2001Q2 2001Q3 2001Q4 2002Q1 2002Q2 CITY1100.5210

[R] Adding List Elements To A Data Frame

2013-07-19 Thread Pete Brecknock
Hi I am trying to add the contents of the list myList to a new column z in the data frame myDataframe myList - list(c(A1,B1), c(A2,B2,C2), c(A3,B3)) myDataframe - data.frame(x=c(1,2,3), y=c(R,S,T)) Would like to produce x y z 1 R A1,B1 2 S A2,B2,C2 3 T A3,B3 where z is a character

Re: [R] Adding List Elements To A Data Frame

2013-07-19 Thread Pete Brecknock
Thanks Brian. Perfect. Brian Diggs wrote On 7/19/2013 12:54 PM, Pete Brecknock wrote: Hi I am trying to add the contents of the list myList to a new column z in the data frame myDataframe myList - list(c(A1,B1), c(A2,B2,C2), c(A3,B3)) myDataframe - data.frame(x=c(1,2,3), y=c(R,S,T

Re: [R] Ordering a matrix by row value in R2.15

2013-03-24 Thread Pete Brecknock
fitz_ra wrote I know this is posted a lot, I've been through about 40 messages reading how to do this so let me apologize in advance because I can't get this operation to work unlike the many examples shown. I have a 2 row matrix temp [,1] [,2] [,3] [,4] [,5]

Re: [R] Integrate with vectors and varying upper limit

2013-03-24 Thread Pete Brecknock
sunny0 wrote I'd like to integrate vectors 't' and 'w' for log(w)/(1-t)^2 where i can vary the upper limit of the integral to change with each value of 't' and 'w', and then put the output into another vector. So, something like this... w=c(.33,.34,.56) t=c(.2,.5,.1) k-c(.3,.4,.5)

Re: [R] Ordering Table Columns

2013-03-02 Thread Pete Brecknock
cdouglass wrote Hello all, Totally new to this and I'm just doing a frequency distribution analysis on T-shirt sales by size. I have a .csv with 60 orders. I read in the data using read.csv. If I look at the summary() or table() of the data it looks fine, except that the shirt sizes are

Re: [R] Merging value labels into indicator variable.

2013-02-26 Thread Pete Brecknock
tasnuvat wrote I have a vaiable named NAM having value : 1,2,3,4,5,6,7,8,9. I want to make an indicator variable that will take value 1 if NAM=7 or NAM=8 or NAM=9. How can I do that? I usually do: Var001- ifelse(NAM==7,1,0) for the simplest case. [[alternative HTML version deleted]]

Re: [R] Quantiles of a subset of data

2013-02-19 Thread Pete Brecknock
bradleyd wrote Excuse the request from an R novice! I have a data frame (DATA) that has two numeric columns (YEAR and DAY) and 4000 rows. For each YEAR I need to determine the 10% and 90% quantiles of DAY. I'm sure this is easy enough, but I am a new to this. quantile(DATA$DAY,c(0.1,0.9))

Re: [R] Quantiles of a subset of data

2013-02-19 Thread Pete Brecknock
bradleyd wrote Thanks for your help Pete. I can almost get it to work with; by(day,year,quantile) but this only gives me 0% 25% 50% 75% 100%, not the ones I'm looking for, 10% and 90%. I have tried; by(day,year,quantile(c(0.1, 0.9))) but this is rejected by Error in FUN(X[[1L]],

Re: [R] Converting the data in year month day hour and minutes to date

2013-02-19 Thread Pete Brecknock
jdbaba wrote Hi , I am trying to convert the date as factor to date using as.date function in R. I have the date in the following format 2008-01-01 02:30 I tried to use the following command : as.Date(mydata$Date, format=%y-%m-%d ) Can somebody help me with this

Re: [R] Quantiles of a subset of data

2013-02-19 Thread Pete Brecknock
bradleyd wrote That does it, thanks. Do you think you help me a little bit further? I actually have 4 columns, YEAR, DAY, TEMP , and IBI. They are all numeric. I need to calculate the average TEMP and IBI values between the 10% and 90% quantiles for each YEAR. The code *

Re: [R] Quantiles of a subset of data

2013-02-19 Thread Pete Brecknock
bradleyd wrote Thanks Pete. The TRIM argument in the MEAN function tells me how to trim off decimal points, but I am lost as to how to append the mean values of TEMP and IBI between the 10% and 90% quantiles of DAY in each YEAR. DAY is the julian date that an event occurred in certain

Re: [R] doubt with function on R software

2013-02-18 Thread Pete Brecknock
monicamir88 wrote Hello! I have a doubt with the R software. I have this function: results - function(bCODBOD, BOD, VSS, COD, sBOD, sCOD, TSS, TKNpa, T, NH3Ne, DO, Q, TKN, MLSS, NO3Ne, RAS, tanoxic1, tanoxic2, rbCOD, SDNR1, SDNR2, tdanoxic, tanaerobic, IRp, P) { bCOD - bCODBOD*BOD nbCOD -

Re: [R] R function help!

2013-02-18 Thread Pete Brecknock
simonj16 wrote Consider an urn that contains 10 tickets, labelled: 1,1,1,1,2,5,5,10,10,10 I want to draw with replacement n=40 tickets. I am interested in the sum, Y, of the 40 ticket values that I draw Write an R function named urn.model that simulates this experiement. What I have below

Re: [R] assign estimated values

2013-02-10 Thread Pete Brecknock
malaka wrote Hi, I want to assign the ar1 , ma 1 and the intercept estimated by the following code to three variables a, b and c respectively. Can anyone help me with this please? code: a0 = 0.05; a1 = 0.1; b1 = 0.85 nu = rnorm(2500) epsi = rep(0, 2500) h = rep(0, 2500) for (i in

Re: [R] Converting column of strings to boolean

2013-01-26 Thread Pete Brecknock
domcastro wrote Hi I'm trying to convert a column of strings (nominal types) to a set of boolean / binary / logical values. For example, in the column there is red, blue, green and yellow. There are 100 rows and each has a colour. I want to convert the column to 4 columns: red, blue,

[R] Plot Header

2013-01-15 Thread Pete Brecknock
Any recommendations for how I can embed my title below in a single red strip/box across the plot area in the outer margin? I would like to avoid the color appearing in any other area defined by the oma. # Example Plot par(mfrow=c(2,2),mar=c(4,4,2,2), oma = c(1, 1, 3, 1)) plot(rnorm(100),1:100)

Re: [R] Plot Header

2013-01-15 Thread Pete Brecknock
David Winsemius wrote On Jan 15, 2013, at 2:49 PM, Pete Brecknock wrote: Any recommendations for how I can embed my title below in a single red strip/box across the plot area in the outer margin? I would like to avoid the color appearing in any other area defined by the oma. The code

Re: [R] Plot Header

2013-01-15 Thread Pete Brecknock
David Winsemius wrote On Jan 15, 2013, at 3:25 PM, Pete Brecknock wrote: David Winsemius wrote On Jan 15, 2013, at 2:49 PM, Pete Brecknock wrote: Any recommendations for how I can embed my title below in a single red strip/box across the plot area in the outer margin? I would like

Re: [R] how to apply two or more functions to each columns in a time?

2012-12-26 Thread Pete Brecknock
Yao He wrote Dear All: I want to calculate the mean and sd for each column in a data.frame. Taking data(iris) for example: I tried sapply(iris[,-5],mean,na.rm=T) or sapply(iris[,-5],sd,na.rm=T) to calculate the mean and sd .But sapply() transfer a function per time. How to transfer two

Re: [R] how to add a column from another dataset with merge

2012-12-07 Thread Pete Brecknock
kiotoqq wrote I want to add a shorter column to my dataset with the function merge, it should be filled with NAs wo be as long as the other colums, like this: idage 946 856 6 52 5 NA 4 NA 3 NA 1 NA i did this: pa1 - merge(pa1, an1, by=mergeid) and it says

Re: [R] IMPORTANT!!!! PLEASE HELP ME

2012-11-24 Thread Pete Brecknock
jholtman wrote What do you want to do with the samples after you generate them? What are the parameters for the normal distribution? You left a lot of information out. You can generate 500,000 numbers and then store them in a 1x50 matrix quite easily. On Sat, Nov 24, 2012 at 5:03 PM,

Re: [R] IMPORTANT!!!! PLEASE HELP ME

2012-11-24 Thread Pete Brecknock
Jasmin wrote I try to use hansen-hurwitz and horvitz-thompson estimator.So I should generate samples which come from normal distribution (mu=50,sigma=3). I have taken the liberty of scaling the problem down to something more digestible and have changed lines 5 and 7 in your code nsamples=10

Re: [R] Summary statistics for matrix columns

2012-11-23 Thread Pete Brecknock
frespider wrote Hi, it is possible. but don't you think it will slow the code if you convert to data.frame? Thanks Date: Thu, 22 Nov 2012 18:31:35 -0800 From: ml-node+s789695n4650500h51@.nabble To: frespider@ Subject: RE: Summary statistics for matrix columns

Re: [R] Using cumsum with 'group by' ?

2012-11-23 Thread Pete Brecknock
TheRealJimShady wrote Hi Peter, Yes, I did miss an e from the first 'not' in the brackets at the end of the message, sorry. Thanks for that code, but when I use it, it creates a new column called csum which simply contains the values of the variable x . i.e. it just duplicates the values

Re: [R] Summary statistics for matrix columns

2012-11-22 Thread Pete Brecknock
frespider wrote Hi, is there a way I can calculate a summary statistics for a columns matrix let say we have this matrix x - matrix(sample(1:8000),nrow=100) colnames(x)- paste(Col,1:ncol(x),sep=) if I used summary summary(x) i get the output for each column but I need the output

Re: [R] Merging two data frames with different columns names

2012-04-14 Thread Pete Brecknock
Peterso wrote Uwe: I was actually trying to stack one table on top of the other. All column names are the same except for the Part1 and Part 2. My final table should look like the table below. Maybe it is possible to change the names of Part1 and Part 2 to Part? A B C Part 1 0 1 550

[R] Problems downloading file

2012-03-01 Thread Pete Brecknock
:\\temp\\psw09.xls, : cannot open URL 'http://ir.eia.gov/wpsr/psw09.xls' In addition: Warning message: In download.file(http://ir.eia.gov/wpsr/psw09.xls;, c:\\temp\\psw09.xls, : InternetOpenUrl failed: 'The operation timed out' Thanks for any insights. Pete Brecknock -- View this message

Re: [R] Counting value changes

2012-02-18 Thread Pete Brecknock
maris478 wrote Good afternoon, I've encountered a little bit of a problem, would appreciate any help here. I made a small vector consisting of ones and zeros. Something like this x - c(0,1,0,1,0,0,1,0), and all I need is to count how many times 0 becomes 1. Tried various, of what I

Re: [R] finding the subscript of a vector fulfiiling a given condition

2012-02-14 Thread Pete Brecknock
galemago wrote Dear Forum, I just recently started to work with R, I´d like to know if there is a way to give instructions/do operations related to values with different subscripts within a vector. Let´s assume I have a vector like this: A=368369370371 393394395

Re: [R] How to Calculate Percentage of Data within certain SD of Mean

2012-02-05 Thread Pete Brecknock
How about # Read Data nb10 - read.table(http://www.adjoint-functors.net/su/web/314/R/NB10;) # Calculate Stats total = length(nb10[,1]) mean = mean(nb10[,1]) sd = sd(nb10[,1]) # Function ... nSD is the number of SD you are looking at pData - function(nSD){ lo = mean - nSD/2*sd hi =

Re: [R] text command - how to get a white background to cover grid lines

2012-02-05 Thread Pete Brecknock
How about using the legend function ... plot(rnorm(100)) legend(60,2,100 Random Normal Draws,cex=.8,text.col=blue, box.col=red,bg=yellow) You can customize my effort to fit your specific needs HTH Pete Henry wrote New to R - rookie question. I'm a mechanical engineer and enjoying using

Re: [R] replace some values of a column with diffrent values

2012-02-05 Thread Pete Brecknock
Hi Valerie One way would be to use the match function. # Your Data u =data.frame(coe=c(0,0,0,0,0,0,0,0), name=c(Time,Poten,AdvExp,Share,Change,Accounts,Work,Rating)) v = data.frame(coeff=c(0.7272727,0.322,0.0500123), enter=c(Accounts,Time,Poten)) # Match

Re: [R] combining data structures

2012-02-04 Thread Pete Brecknock
of time required to traverse the link, its name etc. That said, my thought was that the situation was too simple to fire up a full-blown object system beyond what R provides natively. I guess it's like making a data frame that has some 3-d elements. On 2/3/2012 9:32 PM, Pete Brecknock wrote

Re: [R] combining data structures

2012-02-03 Thread Pete Brecknock
Not entirely sure why you would want a data.frame that has multiple entries in one of the columns (Connect.down) but leaving that aside is the following of any use? nn=list() nn[[1]] = list(Node = 1, Connect.up = c(NULL), Connect.down = c(2,3)) nn[[2]] = list(Node = 2, Connect.up = c(1),

Re: [R] Conditional cumulative sum

2012-01-26 Thread Pete Brecknock
Axel Urbiz wrote Dear List, I'll appreciate your help on this. I'm trying to create a variable as in cumsum_y.cond1 below, which should compute the cumulative sum of y conditional on the value of cond==1. set.seed(1) d - data.frame(y= sample(c(0,1), 10, replace= T),

Re: [R] graph paper look

2012-01-18 Thread Pete Brecknock
Erin Hodgess-2 wrote Dear R People: Short of doing a series of ablines, is there a way to produce graph paper in R please? Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto:

Re: [R] problem with table.CAPM in PerformanceAnalytics

2012-01-15 Thread Pete Brecknock
Dom Pazzula wrote All, I'm attempting to run this: table.CAPM(series[,Strat.Return,drop=FALSE],series[,spy.Return,drop=FALSE]) and getting this error Error in as.vector(data[, i]) : subscript out of bounds I've searched around and cannot find a solution to the problem.  I've used

Re: [R] add column with values found in another data frame

2012-01-14 Thread Pete Brecknock
jdog76 wrote I am positive this problem has a very simple solution, but I have been unable to find it, so I am asking for your help. I need to know how to look something up in one data frame and add it as a column in another. If I have a data frame that looks like this: frame1 ID

Re: [R] Display number in currency notation with commas

2012-01-02 Thread Pete Brecknock
eigenvalet wrote How can I display a number as currency including a $ sign and commas? -- View this message in context: http://r.789695.n4.nabble.com/Display-number-in-currency-notation-with-commas-tp4253460p4253460.html Sent from the R help mailing list archive at Nabble.com.

[R] Renaming Within A Function

2011-12-22 Thread Pete Brecknock
I am trying to rename column names in a dataframe within a function. I am seeing an error (listed below) that I don't understand. Would be grateful of an explanation of what I am doing wrong and how I should rewrite the function to allow me to be able to rename my variables. Thanks. # Test

Re: [R] Group several variables and apply a function to the group

2011-12-04 Thread Pete Brecknock
Aurélien PHILIPPOT wrote Dear R-experts, I am struggling with the following problem, and I am looking for advice from more experienced R-users: I have a data frame with 2 identifying variables (comn and mi), and an output variable (x). comn is a variable for a company and mi is a variable

Re: [R] lapply and Two TimeStamps as input

2011-10-31 Thread Pete Brecknock
alaios wrote: Dear all, I have a function that recognizes the following format for timestamps %Y-%m-%d %H:%M:%S my function takes two input arguments the TimeStart and TimeEnd I would like to help me create the right list with pairs of TimeStart and TimeEnd which I can feed to lapply

Re: [R] Extracting dataframe rows containing NAs in one column

2011-10-25 Thread Pete Brecknock
kaallen wrote: Hi, I am working on a data set which looks like this: head(temp) Day Month Year PW ROW 1 1 1 1959 NA 6.40 2 2 1 1959 6.65 6.35 3 3 1 1959 2.50 3.60 4 4 1 1959 0.60 2.25 5 5 1 1959 0.85 0.30 6 6 1 1959 0.00 2.20 I am

Re: [R] column subtraction by row

2011-10-25 Thread Pete Brecknock
Vining, Kelly wrote: Dear UseRs, I have a data frame that looks like this: head(test2) attributes start end StemExplant Callus RegenPlant 1 LTR_Unknown 120 535 3.198 1.931 1.927 3 LTR_Unknown 2955 3218 0.541 0.103 0.613 6 LTR_Unknown 6210 6423

Re: [R] How to change the scale of the Y axis?

2011-10-07 Thread Pete Brecknock
feargalr wrote: I am currently trying to create 3 histograms from 3 sets of data and in order to compare them I need them all to have a common scale, the Y axis is the only place its a problem, as one histogram only goes up to 4, another 5, and another 7 on the Y axis and obviously they all

Re: [R] Keep ALL duplicate records

2011-10-02 Thread Pete Brecknock
Erik Svensson wrote: Hello, In a data frame I want to identify ALL duplicate IDs in the example to be able to examine OS and time. (df-data.frame(ID=c(userA, userB, userA, userC), OS=c(Win,OSX,Win, Win64), time=c(12:22,23:22,04:44,12:28))) IDOS time 1 userA Win 12:22

Re: [R] Saving a list as a Matrix

2011-09-03 Thread Pete Brecknock
wizykid wrote: Hi there. I went through the manual but I couldn't find a solution for my problem. I have list like this one : lst1 [[1]] [1] 0 1 2 3 [[2]] [1] 0 1 5 [[3]] [1] 2 3 4 and I want to save it as Matrix in Matlab mat format like : 0 1 2 3 0 1 5 0 2 3 4 0

Re: [R] Basic vector logic not working

2011-07-09 Thread Pete Brecknock
DimmestLemming wrote: I am interning in a computer science lab and I'm very new to R. The language basics are clear, but this particular problem isn't: I have a very large dataframe called data which holds data from Halo matches. I'm trying to analyze a certain window such that

Re: [R] Recode numbers

2011-06-01 Thread Pete Brecknock
Lisa wrote: Dear all, I have two sets of numbers that look like a - c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b - c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use “b” to encode “a” so that “a” looks like

[R] zoo column names

2011-05-26 Thread Pete Brecknock
I have a zoo object that contains 2 time series named A-B and V1. When I create a third series V2, the name of the A-B series is changed to A.B. Although I could recreate the names for the 3 series I am wondering if there is a way of preventing the name change from happening ( ... maybe an

Re: [R] zoo column names

2011-05-26 Thread Pete Brecknock
Gabor Grothendieck wrote: On Thu, May 26, 2011 at 7:35 PM, Pete Brecknock lt;peter.breckn...@bp.comgt; wrote: I have a zoo object that contains 2 time series named A-B and V1. When I create a third series V2, the name of the A-B series is changed to A.B. Although I could recreate

Re: [R] ARMA

2011-05-08 Thread Pete Brecknock
boki2b wrote: Hello,Could somebody tell me what is the difference between  theese 3 calls of functionsarma(x,order=c(1,0)), arima(x,order=c(1,0,0)) ar(x,order=1)?I expected same residuals of theese three models,but unexpectably for the first two R requiredinitial value of something

Re: [R] how to calculate the mean of a group in a table

2011-05-07 Thread Pete Brecknock
tornanddesperate wrote: Hi its me again I don't mean to get on your nerves, but the use of R proofs to be a bit more complicated than envisaged. I would like to calculate the mean of a group of values, here wage_accepted. The group is determined by the stage and period, so in the end

Re: [R] Element by Element addition of the columns of a Matrix

2011-04-29 Thread Pete Brecknock
... is the apply function what you are looking for? A=matrix(1,2,4) apply(A,1,sum) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Element-by-Element-addition-of-the-columns-of-a-Matrix-tp3483545p3483628.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] Cointegration test of panel data

2011-04-09 Thread Pete Brecknock
You could try the urca package Also, I would maybe have a look a the CRAN Task View on computational econometrics at http://cran.r-project.org/web/views/Econometrics.html HTH Pete -- View this message in context:

Re: [R] cumsum while maintaining NA

2011-04-02 Thread Pete Brecknock
Here's one way . Lines-x1 x2 x3 x4 x5 x6 NA NA 3 4 NA NA 5 3 4 NA NA NA 7 3 4 4 NA NA 11 3 4 5 NA NA 67 4 4 NA NA NA d - read.table(textConnection(Lines), header = TRUE, colClasses=c(integer)) closeAllConnections() res = t(apply(d, 1, function(x) ave(x,is.na(x),FUN=cumsum))) print(res)

Re: [R] List extraction

2011-03-28 Thread Pete Brecknock
Doesn't use apply but maybe the following will work for you? temp1- data.frame(ID=c(Herb,Shrub),stat=c(4,5),pvalue=c(.03,.04)) temp2- data.frame(ID=c(Herb,Shrub, Tree),stat=c(12,15,13),pvalue=c(.2,0.4,.3)) L-list(a=temp1,b=temp2) d.f = do.call(rbind,L) d.f$tableName = substring(rownames(x),1,1)

[R] Reference Lines Using Grid Graphics

2011-03-11 Thread Pete Brecknock
Hi I would like to be able to add reference lines to a series of plots that are built using the Grid graphics package. These lines should coincide with tick marks which are different on each plot. I can add the lines manually using the grid.lines() function but would like to understand how to

Re: [R] Reference Lines Using Grid Graphics

2011-03-11 Thread Pete Brecknock
Apologies I forgot to include that the reference lines should be for the y axis only. Thanks. Pete -- View this message in context: http://r.789695.n4.nabble.com/Reference-Lines-Using-Grid-Graphics-tp3349185p3349206.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] Reference Lines Using Grid Graphics

2011-03-11 Thread Pete Brecknock
Thanks Gabor. I owe you again. Kind regards Pete -- View this message in context: http://r.789695.n4.nabble.com/Reference-Lines-Using-Grid-Graphics-tp3349185p3349259.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Calculate a mean for several months for several years

2011-02-21 Thread Pete Brecknock
For 5 years set.seed = 1 d=data.frame(year=rep(2007:2011,each=12), month=rep(1:12,5), meanTemp = rnorm(60,10,5)) meanByMonth = ave(d$meanTemp, d$month, FUN = mean)[7:9] HTH Pete -- View this message in context:

Re: [R] From SPSS Syntax to R code

2011-02-12 Thread Pete Brecknock
You might want to take a look at Bob Muenchen's book R for SAS and SPSS Users There is an 80 page preview at .. http://rforsasandspssusers.com/ Additionally, there is lots of documentation for getting started with R on the CRAN website http://cran.r-project.org/ HTH Pete --

Re: [R] Downloading SP monthly data into R

2011-02-11 Thread Pete Brecknock
1. Using the quantmod package. Look at ?getSymbols e.g. getSymbols(^GSPC,src=yahoo) then use the to.monthly function 2. Using the tseries package . Look at ?get.hist.quote e.g. get.hist.quote(instrument = ^GSPC, start = as.yearmon(Jan 1950) ,compression = m, quote = Close) There

Re: [R] expression for index of pairwise combinations

2011-02-09 Thread Pete Brecknock
If I have understood correctly, then as an example for 4 columns how about d=data.frame(C1=c(1,1,1,1,1),C2=c(2,2,2,2,2),C3=c(3,3,3,3,3),C4=c(4,4,4,4,4)) combs=combn(paste(C,seq_len(4),sep=),2,simplify=FALSE) one = sapply(combs,function(x) d[x[1]]) two = sapply(combs,function(x) d[x[2]])

Re: [R] problem subsetting a data frame

2011-02-03 Thread Pete Brecknock
try subset(D, D$x 5|D$y 5) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/problem-subsetting-a-data-frame-tp3258981p3259360.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing

Re: [R] Select just numeric values from rows

2011-02-02 Thread Pete Brecknock
Terry Any good? list -A B C N1 N2 N3 N4 N5 N6 N7 N8 N9 N10 Apples Bananas Peaches 1 2 3 4 5 6 7 8 9 10 Oranges Kumquats Plums 1 1 3 5 5 5 7 6 6 12 Pears Kiwis Grapes 2 4 6 8 5 6 7 6 9 1 d = read.table(textConnection(list), header=TRUE) Nrowsums =

Re: [R] time bin sum

2011-02-01 Thread Pete Brecknock
Jessica Any good? lines -DateTime, Q 2004-12-09 15:30:01, 2 2004-12-09 15:30:01, 1 2004-12-09 15:30:06, 1 2004-12-09 15:30:14, 5 2004-12-09 15:30:21, 1 2004-12-09 15:30:22, 11 2004-12-09 15:30:24, 4 2004-12-09 15:30:32, 1 2004-12-09 15:30:32, 1 2004-12-09 15:30:32, 3 2004-12-09 15:30:41, 4 d =

Re: [R] Finding the correlation coefficient of two stocks

2011-01-30 Thread Pete Brecknock
Dieter is correct, the lengths of the 2 series are different Try s = merge(s1,s2) corr = cor(s[,Close.s1],s[,Close.s2],use=pairwise.complete.obs) print(corr) HTH Pete -- View this message in context:

Re: [R] Help plz

2011-01-30 Thread Pete Brecknock
Typing ? (no quotes) followed by a topic of interest will throw up the R Help documentation. 1. Have a look at ?runif 2. Try ?subset and ?cumsum 3. Look at ?rle. Use in conjunction with cumsum and maybe ifelse. HTH Pete -- View this message in context:

Re: [R] How to do a moving window on standard deviation

2011-01-30 Thread Pete Brecknock
One way is to convert your data into a zoo object and use the rollapply function # Your data lines = Date Close 2011-01-28 56.42 2011-01-27 57.37 2011-01-26 56.48 2011-01-25 56.39 2011-01-24 55.74 2011-01-21 55.46 d = read.table(textConnection(lines), header = TRUE) # create zoo object

Re: [R] How to do a moving window on standard deviation

2011-01-30 Thread Pete Brecknock
how about ... j=NULL for(i in 4: length(xyz$Close)) { j[i] = sd(xyz$Close[i-3:i]) } print(j) -- View this message in context: http://r.789695.n4.nabble.com/How-to-do-a-moving-window-on-standard-deviation-tp3247566p3247634.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] How to do a moving window on standard deviation

2011-01-30 Thread Pete Brecknock
I believe there are two reasons why your code doesn't work 1. You should replace sd(Close[i]:Close[(i-3)]) with sd(Close[(i-3):i]). This will ensure you select the appropriate obsevations to feed in the sd function. 2. Per Ray's point above, you need to output the calculated value of sd

Re: [R] sapply puzzlement

2011-01-27 Thread Pete Brecknock
In addition to what has already been suggested you could use .. mapply(function(x,y) x-y, z,means) which returns V1 V2 [1,] 0.333 -2.7142857 [2,] NA 7.2857143 [3,] -0.667 -3.7142857 [4,] -6.667 NA [5,] NA -0.7142857 [6,]

Re: [R] How do I fix this ?

2011-01-26 Thread Pete Brecknock
Eric Your problem lies in the way cumprod deals with NAs If you look at ?cumprod you will see An NA value in x causes the corresponding and following elements of the return value to be NA Not sure what behaviour you want to see on encountering an NA (ignore it, restart the cumprod process,

Re: [R] $ operator is invalid for atomic vectors

2011-01-18 Thread Pete Brecknock
Amy It would have been helpful if you had sent your R code of how you constructed the sab object. If you have a data.frame, the subset command you are having trouble with should work fine. See below. # Working Example sab = data.frame(group=c('Group A', 'Group A', 'Group C', 'Group B', 'Group

Re: [R] data frame column name change

2011-01-17 Thread Pete Brecknock
or d = data.frame(Col1=c(1,2,3),Col2=c(2,3,4),Col3=c(3,4,5)) names(d) names(d)[1] = NewName1 names(d) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/data-frame-column-name-change-tp3220684p3221214.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] How to doulbe all the value on a matrix

2011-01-17 Thread Pete Brecknock
If I have understood your question correctly, how about the following ... m = matrix(c(7,11,15,17,10,19,4,18,18), nrow = 3, ncol=3) sum_m = sum(m) new_m = summ-m HTH Pete -- View this message in context:

Re: [R] How to doulbe all the value on a matrix

2011-01-17 Thread Pete Brecknock
typo ... should have been m = matrix(c(7,11,15,17,10,19,4,18,18), nrow = 3, ncol=3) sum_m = sum(m) new_m = sum_m-m -- View this message in context: http://r.789695.n4.nabble.com/How-to-doulbe-all-the-value-on-a-matrix-tp3221213p3221216.html Sent from the R help mailing list archive at

Re: [R] How to doulbe all the value on a matrix

2011-01-17 Thread Pete Brecknock
try ... new_m = m[c(2,7,8),c(1,4,6,7)] HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/How-to-doulbe-all-the-value-on-a-matrix-tp3221213p3221234.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] How to doulbe all the value on a matrix

2011-01-17 Thread Pete Brecknock
I believe you want to select a subset of rows and subset of columns of your original matrix m. If you had wanted only the first row of m, you could have used m[1,] Alternatively, if you had wanted only the second column of m then you could have used m[,2] m[1,2] would give you the element at

Re: [R] a remove question

2011-01-16 Thread Pete Brecknock
or rm(list=ls(pattern=^NY)) if you only want those objects that begin with NY ... HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/a-remove-question-tp3220411p3220562.html Sent from the R help mailing list archive at Nabble.com.