Re: [R] Two conditions selection

2015-08-04 Thread Pete Brecknock
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) df <- data.frame(cycle,col,values) # Subset data frame df df[cycle==1 & col=="blue",] HTH Pete -- View this m

[R] Latest Xorg updates broke R x11()

2015-07-27 Thread Boyd, Leslie (Pete)
Hello, Have 15 RedHat EL6 workstations patched to current. Over the weekend the kernel was patched to 6.7 and the xorg-x11-server and our R-3.1.2 will not open a xterm window. It appears to select a portion of the screen and lock onto it. This section can be moved a

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 B

Re: [R] sapply function and poisson distribution

2015-01-03 Thread Pete Brecknock
ng sapply function? > thank u in advance How about using mapply, the multivariate version of sapply? Based on your example ... mapply(function(x,y) rpois(x,y), c(1,2),c(0.1,0.8)) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/sapply-function-and-poisson-dist

[R] help with xts

2014-05-18 Thread Pete
I have 3 xts objects: test, cond1, cond2 You can download here: https://dl.dropboxusercontent.com/u/102669/obj.rar My problem is very simple. test [ cond1 < cond2] = NA THIS WORKS test [ cond1 < cond2] = -test [ cond1 < cond2] THIS DOESN'T WORKS Why? My objecti

Re: [R] multiple plots

2014-03-08 Thread Pete Brecknock
5) d<-c(0.786,0.217,0.538,0.513,0.870,0.326,0.647,0.217) # Plot plot(c,a, type="o", col="red", ylim=c(min(a,b,d),max(a,b,d))) lines(c,b, type="o",col="blue") lines(c,d, type="o",col="green") HTH Pete -- View this message in cont

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

2014-03-08 Thread Pete Brecknock
<- read.table(textConnection(txt), header = TRUE) closeAllConnections() ddply(d,~ID,function(x){x[which.max(x$B),]}) # Returns ID A B C 1 1 12 36 2 2 2 33 30 2 3 3 83 23 2 4 4 82 36 2 5 5 77 35 2 6 6 76 35 2 7 7 21 30 2 8 8 30 36 2 9 9 21 35 2 HTH

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&

Re: [R] Dataset to single column matrix

2014-01-07 Thread Pete Brecknock
1 > 2 > 3 > 4 > 5 > 6 > 7 > 8 > 9 > 10 > 11 > 12 > etc. > > Any suggestions? > Thanks in advance Krishia Is this what you are looking for? # Create example matrice m <- matrix(c(1,2,3,4,5,6,7,8,9,10,11,12), nrow=4, byrow=TRUE) # Create vector v &l

Re: [R] midpoint between two dates

2013-11-17 Thread Pete Brecknock
<- data.frame(id=c(1,2,3),date1,date2) df$mid <- df$date1 + floor((df$date2-df$date1)/2) print(df) id date1 date2 mid 1 1 2013-10-10 2013-10-20 2013-10-15 2 2 2013-11-15 2013-11-20 2013-11-17 3 3 2013-12-25 2013-12-30 2013-12-27 HTH Pete -- View this message

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

2013-11-01 Thread Pete Brecknock
6.5925 108.7437 110.5549 111.9343 112.6704 113.6201 115.3020" df <- read.table(textConnection(text), header=TRUE, check.names=FALSE) #Create zoo object d <- t(df[,-1]) ind <- as.yearqtr(names(df)[-1]) z <- zoo(d,ind) # Plot plot(z, plot.type="single", col=1:5, lwd=2) legend(

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" &

[R] Adding List Elements To A Data Frame

2013-07-19 Thread Pete Brecknock
ta.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 string holding the contents of the different elements of the list. Any thoughts greatly appreciated. Pete -- View this message in

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

2013-03-24 Thread Pete Brecknock
subdivisions=1000)) # Output [,1] [,2][,3] value-0.4017303 -0.6249136 -0.9373696 abs.error2.798235e-05 9.17413e-05 9.209191e-05 subdivisions 32 208 91 message "OK" "OK"&quo

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

2013-03-24 Thread Pete Brecknock
to switch with the sort. Maybe consider the order function orig <- matrix(c(10,20,30,3,1,2), nrow=2, byrow=TRUE) new <-t(apply(orig,1,function(x) x[order(orig[2,])])) > orig [,1] [,2] [,3] [1,] 10 20 30 [2,]312 > new [,1] [,2] [,3] [1,] 20 30 10 [2

[R] data.frame with NA

2013-03-18 Thread Pete
I have this little data.frame http://dl.dropbox.com/u/102669/nanotna.rdata Two column contains NA, so the best thing to do is use na.locf function (with fromLast = T) But locf function doesn't work because NA in my data.frame are not recognized as real NA. Is there a way to substitute fake NA

[R] Find NA in xts object

2013-03-16 Thread Pete
Hi to all, i'm new to R I have an xts object. Can i find: a) how many NA are in my object ? b) eventually where (in which line) they are Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the pos

Re: [R] Ordering Table Columns

2013-03-02 Thread Pete Brecknock
nk you want to have a look at factors Typing ?factor will throw up the relevant help pages # Your Data tbl <- read.table(header = TRUE, text = " ShirtSize Number L 20 M 20 S 11 XL 7 XXL 2 ") # ShirtSize Alphabetical tbl[tbl$ShirtSize,] # Reorde

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

2013-02-26 Thread Pete Brecknock
self-contained, reproducible code. How about something like ... NAM = c(1,2,3,4,5,6,7,8,9) ifelse(NAM>=7,1,0) # or ifelse(NAM %in% c(7,8,9),1,0) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Merging-value-labels-into-indicator-variable-tp4659703p4659705.html Sent fr

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 occu

Re: [R] Quantiles of a subset of data

2013-02-19 Thread Pete Brecknock
ok at trim argument of the mean function ?mean Pete -- View this message in context: http://r.789695.n4.nabble.com/Quantiles-of-a-subset-of-data-tp4659063p4659086.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mai

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

2013-02-19 Thread Pete Brecknock
HTML version deleted]] > > __ > R-help@ > 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-contai

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,

Re: [R] Quantiles of a subset of data

2013-02-19 Thread Pete Brecknock
t;> quantile(DATA$DAY,c(0.1,0.9)) > 10% 90% > 12 29 > > But this is for the entire 4000 rows, when I need it to be for each YEAR. > Is there no way to use a "by" argument in the quantile function? > > Thanks for any help you can provide. > David check out

Re: [R] R function help!

2013-02-18 Thread Pete Brecknock
> > Follow up question: > > Use urn.model to generate a sample y={y1,...,y25) of n=25 observed sums. Any good? ticket.ns<-c(1,1,1,1,2,5,5,10,10,10) draw=NULL for (i in 1:25){ draw[i] <- sum(sample(ticket.ns,40,replace=TRUE)) } print(draw) HTH Pete -- View this message

Re: [R] doubt with function on R software

2013-02-18 Thread Pete Brecknock
;) > > return(res) } > > > > Where, for example, the values of the variables are: > results(1.6, 140, 60, 300, 70, 132, 70, 1.5, 12, 0.5, 2, 22464, 35, 3000, > 6, 0.6, 0.104, 0.0625, 80, 0.22, 0.31, 0.0625, 0.0625, 2, 6) > > I want to take the v

Re: [R] assign estimated values

2013-02-10 Thread Pete Brecknock
7;t work for me in the form you posted it. However, changing ... arma(epsi, order=c(1,1)) to mod = arima(epsi, order=c(1,0,1)) You can extract the parameters of interest using a= mod$coef["ar1"] b= mod$coef["ma1"] c= mod$coef["intercept"] HTH Pete

Re: [R] Converting column of strings to boolean

2013-01-26 Thread Pete Brecknock
to 4 columns: red, blue, green,yellow and then > either 1 or 0 put in the relevant row. > Thanks maybe model.matrix will help # d is my understanding of your data d<-factor(c("red","green","red","blue","green","yellow",&qu

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 >>>&

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 an

[R] Plot Header

2013-01-15 Thread Pete Brecknock
) plot(rnorm(100),1:100) plot(rnorm(100),1:100) plot(rnorm(100),1:100) # Title title("MY TITLE", outer = TRUE, cex = 1.5, adj=0, col="blue", font=2) Thanks for any pointers Pete -- View this message in context: http://r.789695.n4.nabble.com/Plot-Header-tp4655654.html Sent fro

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

2012-12-26 Thread Pete Brecknock
ted, minimal, self-contained, reproducible code. Or maybe using apply # data d <- iris[,-5] # apply function a <-data.frame(apply(d, 2, function(x) c(mean=mean(x), sd=sd(x # print(a) output Sepal.Length Sepal.Width Petal.Length Petal.Width mean5.843 3.057 3

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

2012-12-07 Thread Pete Brecknock
A > > i did this: > pa1 <- merge(pa1, an1, by="mergeid") > > and it says "'by' must specify uniquely valid column(s)" how about ... #Data d1<-data.frame(id=c(9,8,6,4,4,3,1)) d2<-data.frame(id=c(9,8,6),age=c(46,56,52)) # Left Merge d<-merge(d1,

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

2012-11-24 Thread Pete Brecknock
les=10 sampsize=5 i=0 y=matrix(rnorm(nsamples*sampsize,50,3),nrow=nsamples) s=matrix(NA,10,5) for(i in 1:10){ s[i,]=sample(y,5,replace=T) } HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/IMPORTANT-PLEASE-HELP-ME-tp4650676p4650692.html Sent from the R help mailin

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

2012-11-24 Thread Pete Brecknock
that you are trying to solve? > Tell me what you want to do, not how you want to do it. > > __ > R-help@ > mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-projec

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

2012-11-23 Thread Pete Brecknock
;>>> >>>> >>>> If you reply to this email, your message will be added to the >>>> discussion >>>> below: >>>> >>>> http://r.789695.n4.nabble.com/Using-cumsum-with-group-by-tp4650457p4650

Re: [R] Summary statistics for matrix columns

2012-11-23 Thread Pete Brecknock
> NAML Then maybe x <- matrix(sample(1:8000),nrow=100) colnames(x)<- paste("Col",1:ncol(x),sep="") apply(x,2,function(x) c(Min=min(x), "1st Qu" =quantile(x, 0.25,names=FALSE), Median = q

Re: [R] Summary statistics for matrix columns

2012-11-22 Thread Pete Brecknock
Median : 3631 3376 > Mean: 3804 3617 > Sd : > 3rd Qu.:5772 5544 > IQR: > Max. :79527779 > > Is there an easy way? > > Thanks How about ... x <- matrix(sample(1:8000),nrow=100) colnames(x)<- paste("

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

2012-04-14 Thread Pete Brecknock
ep2) d12 <- rbind(part1,part2) # Approach 2 part1 <- data.frame(d1,rep1) names(part1)<- c("blk","A","B","C","part") part2 <- data.frame(d2,rep2) names(part2)<- c("blk","A","B","C",

[R] [R-pkgs] New package joineR

2012-04-02 Thread Pete Philipson
orrelation structure, and maximum likelihood estimation for a class of random effects joint models. Best wishes, Pete. Pete Philipson Lecturer in Statistics School of Computing, Engineering and Information Sciences Northumbria University email: pete.philip...@northumbria.ac.uk [[alte

[R] Problems downloading file

2012-03-01 Thread Pete Brecknock
; Error in download.file("http://ir.eia.gov/wpsr/psw09.xls";, "c:\\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

Re: [R] Counting value changes

2012-02-18 Thread Pete Brecknock
times "0" becomes "1". > Tried various, of what I thought, methods with built in functions. Didn't > get any further. > > Thank you very much. > How about ... x <- c(0,1,0,1,0,0,0,0) sum(rle(x)$values) HTH Pete -- View this message in context: http:

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

2012-02-14 Thread Pete Brecknock
My problem is that I don´t find a way to define the vector subscripts as a > variable, that I believe is what I need to solve this problem. Is that > possible? > Thanks a lot, hope to come back often in this forum, > G. > How about ... A <- c(368,369,370,371,393,394,395) which.m

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

2012-02-05 Thread Pete Brecknock
(coeff=c(0.7272727,0.322,0.0500123), enter=c("Accounts","Time","Poten")) # Match Function updates = v[match(u$name,v$enter),"coeff"] u$coe = ifelse(!is.na(updates), updates, u$coe) HTH Pete valerie wrote > > Hi, > > I have t

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 - roo

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

2012-02-05 Thread Pete Brecknock
quot;, sep="")) # 93% print(paste("Percent of data within 4 SD is ",pData(4),"%", sep="")) # 96% print(paste("Percent of data within 5 SD is ",pData(5),"%", sep="")) # 97% print(paste("Percent of data within 6 SD is ",p

Re: [R] combining data structures

2012-02-04 Thread Pete Brecknock
. I am not familiar with the diagram package or the examples you describe. Why the desire to create a data frame? Why not just use a list? HTH Pete dkStevens wrote > > Thanks for the reply. Two things - I must have something missing because > copying and pasting your example gave me

Re: [R] combining data structures

2012-02-03 Thread Pete Brecknock
nnect.down 1 1 NULL 2, 3 2 21 4, 5 3 3 NULL 2, 3 4 4 1 4, 5 HTH Pete dkStevens wrote > > Group > > It's unlikely I'

Re: [R] Conditional cumulative sum

2012-01-26 Thread Pete Brecknock
cond= sample(c(0,1), 10, replace= T)) d$cumsum_y.cond1 = cumsum(d$y & d$cond) # Output y cond cumsum_y.cond1 1 00 0 2 00 0 3 11 1 4 10 1 5 0 1 1 6 10 1 7 11

Re: [R] graph paper look

2012-01-18 Thread Pete Brecknock
> and provide commented, minimal, self-contained, reproducible code. > How about ... x = rnorm(100) y = rnorm(100) plot(x,y) grid() HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/graph-paper-look-tp4308827p4308906.html Sent from the R help mailing list archive a

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

2012-01-15 Thread Pete Brecknock
0. Tracking Error 0.7447 Active Premium 0.3694 Information Ratio 0.4960 Treynor Ratio 1.8885 HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/problem-with-table-CAPM-in-PerformanceAna

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

2012-01-14 Thread Pete Brecknock
this: > > ID age > 1 Guy1 20 > 2 Guy2 33 > > I know this must be simple, but I couldn't find the solution by searching. > > thanks so much > Jeremy > How about frame2$age = frame1[match(frame2$ID, frame1$ID),"age"] print(frame2) ID

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

2012-01-02 Thread Pete Brecknock
ducible code. > One way myNum= paste("$",format(myNum, big.mark=","),sep="") HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Display-number-in-currency-notation-with-commas-tp4253582p4253695.html Sent from the R help mailing li

[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 Fun

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

2011-12-04 Thread Pete Brecknock
lp > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > One way would be to use the aggregate function. # Your Data ... # Note: I have removed the quotes off the output variable x comn&

Re: [R] lapply and Two TimeStamps as input

2011-10-31 Thread Pete Brecknock
e("2011-01-01 11:30:00","%Y-%m-%d %H:%M:%S")), c(strptime("2010-12-01 10:00:00","%Y-%m-%d %H:%M:%S"), strptime("2010-12-25 06:00:00","%Y-%m-%d %H:%M:%S"))) lapply(myListStartEnd,function(x) x[2]

Re: [R] column subtraction by row

2011-10-25 Thread Pete Brecknock
4.650 9.081 213 4 LTR_Unknown 9658 10124 0.238 0.117 0.347 466 5 LTR_Unknown 14699 14894 3.545 3.625 2.116 195 6 LTR_Unknown 33201 33474 1.275 1.194 0.591 273 HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/column-subtraction-by-ro

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

2011-10-25 Thread Pete Brecknock
> I am sure others will have cleaner approaches but how about # Data temp = data.frame(Day=1:6,Month=1, Year=c(NA,1959,NA,1959,1959,1959), PW=c(6,7,8,NA,10,11)) # Extract Any Row Containing an NA myNAs = temp[apply(temp,1,function(x) any(is.na(x))),] HTH Pete -- View this message in

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

2011-10-07 Thread Pete Brecknock
runif(100) par(mfrow = c(2,1)) hist(d1, ylim=c(0,50)) hist(d2, ylim=c(0,50)) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/How-to-change-the-scale-of-the-Y-axis-tp3883843p3884112.html Sent from the R help mailing list archive at Nabble.com. _

Re: [R] Keep ALL duplicate records

2011-10-02 Thread Pete Brecknock
e > [1] FALSE FALSE TRUE FALSE > i.e. not all user A records are found > > With unique(df$ID) > [1] userA userB userC > Levels: userA userB userC > i.e. one of each ID is found --] > > Erik Svensson > How about ... # All records ALL_RECORDS <- df[df$ID==df$I

Re: [R] Saving a list as a Matrix

2011-09-03 Thread Pete Brecknock
save it as Matrix in Matlab mat format like : > 0 1 2 3 > 0 1 5 0 > 2 3 4 0 > > > can any body help me ? Appreciate your help and thanks in advance. > > Reza > Not pretty but this works ... lst1 = list(c(0,1,2,3),c(0,1,5),c(2,3,4)) t(sapply(lst1, function(x) c(x,

[R] Loop with random sampling and write.table

2011-09-03 Thread Pete Pete
Hi! I need to perform this simple sampling function several hundred times: x1=as.character(rnorm(1000, 100, 15)) x2=as.character(rnorm(1000, 150, 10)) y1=as.data.frame(x1,x2) sample1=as.data.frame(sample(y1$x1, 12, replace = FALSE, prob = NULL)) sample1 write.table(sample1, "sample1.txt", sep="

Re: [R] Basic vector logic not working

2011-07-09 Thread Pete Brecknock
e data d = data.frame(age=1:20, names=letters[1:20]) # 1. subset using [ d[d$age>10 & d$age<16,] # 2. subset using subset function subset(d,d$age>10 & d$age<16) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Basic-vector-logic-not-working-tp3656465p36565

Re: [R] Reshape from long to wide format with date variable

2011-07-07 Thread Pete Pete
Thanks, Josh! The index variable (time) was my problem. My R skills are too low! :) Problem solved! -- View this message in context: http://r.789695.n4.nabble.com/Reshape-from-long-to-wide-format-with-date-variable-tp3648833p3650995.html Sent from the R help mailing list archive at Nabble.com.

[R] Reshape from long to wide format with date variable

2011-07-06 Thread Pete Pete
Hi, I need to reshape my dataframe from a long format to a wide format. Unfortunately, I have a continuous date variable which gives me headaches. Consider the following example: > id=c("034","034","016","016","016","340","340") > date=as.Date(c("1997-09-28", "1997-10-06", "1997-11-04", "2000-09-

[R] chull increase number of points

2011-06-28 Thread pete
Dear R-help, I am using the chull function to create a convex hull of a series of about 20,000 data points. A [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do

[R] chull increase number of points

2011-06-28 Thread pete
Dear R-help, I am using the chull function to create a convex hull of a series of about 20,000 data points. A pain is temporary, glory is forever! Powered by Linux. www.linux.org Scanned for viruses using ClamAV. www.clamav.net. [[alternative HTM

Re: [R] Recode numbers

2011-06-01 Thread Pete Brecknock
t want to use “b” to encode “a” so that “a” looks like > > a1<- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17, > 18, 2, 4, 15, 19) > > Does anyone have a suggestion how to deal with this? Thank you in advance. > > Lisa > is a1 = b[a] what you are

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 > <peter.breckn...@bp.com> wrote: >> I have a zoo object that contains 2 time series named "A-B" and "V1". >> >> When I create a third series "V2", the nam

[R] zoo column names

2011-05-26 Thread Pete Brecknock
quot;) d.z = zoo(d,1:3) # Create new variable "V2" # col name changes from "A-B" to "A.B" d.z$V2 = d.z[,"V1"] *100 # recreate col names names(d.z) = c(names(d),"V2") #- Thanks Pete -- View this

Re: [R] ARMA

2011-05-08 Thread Pete Brecknock
quot;intercept" is the "intercept" ar(d,aic=FALSE, order.max=1,method="ols",intercept=TRUE, demean=FALSE) > 1 > -0.1057 > Intercept: -0.07054 (0.1731) There is a nice document on CRAN that you may find useful. http://cran.r-project.org/doc/contrib/Ricci

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

2011-05-07 Thread Pete Brecknock
lConnections() # 1. using the aggregate function aggregate(d$wage_accepted, list(period=d$period, stage=d$stage), FUN=mean) # 2. using the by function by(d$wage_accepted,list(d$period,d$stage),FUN=mean) As for tutorial resources, I would recommend visiting CRAN at http://cran.r-project.org/ .

Re: [R] Creating binary variable depending on strings of two dataframes

2011-05-06 Thread Pete Pete
Gabor Grothendieck wrote: > > On Tue, Dec 7, 2010 at 11:30 AM, Pete Pete <noxyp...@gmail.com> > wrote: >> >> Hi, >> consider the following two dataframes: >> x1=c("232","3454","3455","342","13") >>

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: http://r.789695.n4.nabble.com/Cointegration-test-of-

Re: [R] cumsum while maintaining NA

2011-04-02 Thread Pete Brecknock
x,is.na(x),FUN=cumsum))) print(res) x1 x2 x3 x4 x5 x6 [1,] NA NA 3 7 NA NA [2,] 5 8 12 NA NA NA [3,] 7 10 14 18 NA NA [4,] 11 14 18 23 NA NA [5,] 67 71 75 NA NA NA HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/cumsum-while-maintaining-NA-tp3421513p3422619.ht

Re: [R] List extraction

2011-03-28 Thread Pete Brecknock
p1,b=temp2) d.f = do.call("rbind",L) d.f$tableName = substring(rownames(x),1,1) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/List-extraction-tp3413374p3413564.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. __ R-help@r

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

[R] Reference Lines Using Grid Graphics

2011-03-11 Thread Pete Brecknock
generate them on the fly. Any help would be gratefully received. Kind regards Pete ### # FUNCTION MYPLOT ### myplot=function(i,j){ pushViewport(viewport

[R] does rpy support R 2.12.2

2011-03-01 Thread Pete Shepard
Hi, I am getting the following error when I try to run import rpy from the the python IDE: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.6/dist-packages/rpy.py", line 134, in """ % RVERSION) RuntimeError: No module named _rpy2122 RPy module can not

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: http://r.789695.n4.nabble.com/Calculate-a-mean-for-several-months-for

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.

Re: [R] Downloading S&P monthly data into R

2011-02-11 Thread Pete Brecknock
an 1950") ,compression = "m", quote = "Close") There will be many other approaches. HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Downloading-S-P-monthly-data-into-R-tp3302339p3302395.html Sent from the R help mailing list archive at Nabble.c

Re: [R] expression for index of pairwise combinations

2011-02-09 Thread Pete Brecknock
ombs,function(x) d[x[2]]) ret = mapply(cbind,one,two) colnames(ret) = paste("C",1:length(combs),sep="") You will need to change seq_len(4) to seq_len(269) in the second line. HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/expression-for-index-of-pair

[R] (no subject)

2011-02-05 Thread pete
-- View this message in context: http://r.789695.n4.nabble.com/no-subject-tp3262024p3262024.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.

[R] clustering fuzzy

2011-02-05 Thread pete
After ordering the table of membership degrees , i must get the difference between the first and second coloumns , between the first and second largest membership degree of object i. This for K=2,K=3,to K.max=6. This difference is multiplyed by the Crisp silhouette index vector (si). Too it d

Re: [R] clustering fuzzy

2011-02-05 Thread pete
After ordering the table of membership degrees , i must get the difference between the first and second coloumns , between the first and second largest membership degree of object i. This for K=2,K=3,to K.max=6. This difference is multiplyed by the Crisp silhouette index vector (si). Too it d

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 m

Re: [R] Select just numeric values from rows

2011-02-02 Thread Pete Brecknock
ums = apply(d[,sapply(d,is.numeric)],1,sum) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Select-just-numeric-values-from-rows-tp3256237p3256670.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-projec

Re: [R] clustering fuzzy

2011-02-02 Thread pete
After ordering the table of membership degrees , i must get the difference between the first and second coloumns , between the first and second largest membership degree of object i. This for K=2,K=3,to K.max=6. This difference is multiplyed by the Crisp silhouette index vector (si). Too it d

Re: [R] time bin sum

2011-02-01 Thread Pete Brecknock
# Clean up counts[is.na(counts)]=0 colnames(counts) = "Counts" print(counts) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/time-bin-sum-tp3252376p3253400.html Sent from the R help mailing list archive at Nabble.com. __

[R] silhouette fuzzy

2011-01-31 Thread pete
After ordering the table of membership degrees , i must get the difference between the first and second coloumns , between the first and second largest membership degree of object i. This for K=2,K=3,to K.max=6. This difference is multiplyed by the Crisp silhouette index vector (si). Too it de

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 fo

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
object d.z=zoo(d[,-1],order.by=as.Date(d$Date)) # generate rolling std devs sd.z = rollapply(d.z,5,sd,align="right") # you wanted a data frame df = as.data.frame(merge(d.z,sd.z,all=TRUE)) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/How-to-do-a-movin

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: http://r.789695.n4.nabbl

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: http://r.789695.n4.nabble.com/Finding-the-

Re: [R] sapply puzzlement

2011-01-27 Thread Pete Brecknock
icely. nums = 1:10 nums +c(1,2) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/sapply-puzzlement-tp3243520p3243583.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list

Re: [R] How do I fix this ?

2011-01-26 Thread Pete Brecknock
od process, .). Making things easy for myself (it's late), if you wish to simply ignore an NA the following would work # sample data y2=c(NA,1,2,3,4,5) # ignore NA ave(y2,is.na(y2),FUN=cumprod) HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Ho

  1   2   >