On 7/7/2009 3:06 PM, Mark Knecht wrote:
Hi,
I am apparently not understanding some nuance about either the use
of subset or more likely my ability to test for a numerical match
using '='. Which is it? Thanks in advance.
I've read a data file, reshaped it and then created MyResults by
keeping only lines where the value column is greater than 0. So far so
good. The data in MyResults looks good to me by eye.
The problem comes in when I try to further subset MyResults into
two files, one with PosType=1 and the other with PosType=-1. Looking
PosType = 1 is an assignment. The test is PosType == 1.
Duncan Murdoch
at the dimension of the results there's no change. It didn't work
which is verified by eye. However if I test for PosType=1 by actually
testing for PosType>0 then it does work.
Is this the general case in R that if I've read data that was
written into a csv file as 1 - it is 1 if I look into the file with a
text editor - that I cannot test for that? Or is some case where I
need to use maybe as.numeric or something else first to ensure R sees
the number the way I'm thinking about the number?
Cheers,
Mark
dim(X)
[1] 25 425
ReShapeX <- melt(X, id = c("Trade", "PosType", "EnDate", "EnTime", "ExDate", "ExTime", "PL_Pos",
"Costs", "Save2"))
dim(ReShapeX)
[1] 10400 11
MyResults <- subset(ReShapeX, value > 0)
dim(MyResults)
[1] 1105 11
MyResults.GroupA <- subset(MyResults, PosType = 1)
dim(MyResults.GroupA)
[1] 1105 11
MyResults.GroupB <- subset(MyResults, PosType = -1)
dim(MyResults.GroupB)
[1] 1105 11
MyResults.GroupA <- subset(MyResults, PosType > 0)
dim(MyResults.GroupA)
[1] 432 11
MyResults.GroupB <- subset(MyResults, PosType < 0)
dim(MyResults.GroupB)
[1] 673 11
______________________________________________
R-help@r-project.org 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-contained, reproducible code.
______________________________________________
R-help@r-project.org 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-contained, reproducible code.