search for: binposneg

Displaying 3 results from an estimated 3 matches for "binposneg".

2009 Jun 30
2
Using functions to change values in a data.frame
...way. However my simple example doesn't work as I expected it to: Here the R example code to cut and paste. The basic idea is to copy positive values of y into p and negative values into l. <START COPY> AddCols = function (MyFrame) { MyFrame$p<-0 MyFrame$l<-0 return(MyFrame) } BinPosNeg = function (MyFrame) { ifelse(MyFrame$y>0, MyFrame$p<-MyFrame$y, MyFrame$l<MyFrame$y) return(MyFrame) } F1 <- data.frame(x=1:10, y=-4:5) F1 F1 <- AddCols(F1) F1 F1 <- BinPosNeg(F1) F1 <END COPY> My results below are weird. After the last function call F1 acts like Bin...
2009 Jul 01
1
running count in data.frame
...then hold 4 until the end. $pc should have stays 0 until line 6 and then gone up to 5 at the end. Any and all inputs appreciated on what I'm doing wrong. Thanks, Mark AddCols = function (MyFrame) { MyFrame$p<-0 MyFrame$l<-0 MyFrame$pc<-0 MyFrame$lc<-0 return(MyFrame) } BinPosNeg = function (MyFrame) { ## Positive y in p column, negative y in l column pos <- MyFrame$y > 0 MyFrame$p[pos] <- MyFrame$y[pos] MyFrame$l[!pos] <- MyFrame$y[!pos] return(MyFrame) } RunningCount = function (MyFrame) { ## Running count of p & l events pos <- (MyFrame$p >...
2009 Jul 01
2
?max (so far...)
...', ll should be 'lowest l'. I get an error message "Error in 1:row : NA/NaN argument" Thanks, Mark AddCols = function (MyFrame) { MyFrame$p<-0 MyFrame$l<-0 MyFrame$pc<-0 MyFrame$lc<-0 MyFrame$pwin<-0 MyFrame$hp<-0 MyFrame$ll<-0 return(MyFrame) } BinPosNeg = function (MyFrame) { ## Positive y in p column, negative y in l column pos <- MyFrame$y > 0 MyFrame$p[pos] <- MyFrame$y[pos] MyFrame$l[!pos] <- MyFrame$y[!pos] return(MyFrame) } RunningCount = function (MyFrame) { ## Running count of p & l events pos <- (MyFrame$p >...