[R] Unexpected behavior in recode{car}

2005-07-27 Thread D. Dailey
Thanks to the R creators for such a great statistical system. Thanks to
the R help list, I have (finally) gotten far enough in R to have a
question I hope to be worth posting.

I'm using the recode function from John Fox's car package and have
encountered some unexpected behavior.

Consider the following example:

## Begin cut-and-paste example
require( car )
set.seed(12345)
nn - sample( c( 2, 4 ), size=50, replace=TRUE )
rr - recode( nn, 2='TWO';4='FOUR' )
table( rr, exclude=NULL )
ss - recode( nn, 2='Num2';4='Num4' )  # Doesn't work as expected
table( ss, exclude=NULL )
tt - recode( nn, 2='TWO'; 4='Num4' )
table( tt, exclude=NULL )
uu - recode( nn, 2='Num2'; 4='FOUR' )
table( uu, exclude=NULL )
## End cut-and-paste example

All but the recoding to ss work as expected: I get a character vector
with 23 instances of either FOUR or Num4 and 27 instances of TWO
or Num2.

But for the ss line, wherein all the strings to be assigned contain a
digit, the resulting vector contains all NAs. Using str(), I note that
ss is a numeric vector.

Is there a tidy way (using recode) to recode numeric values into
character strings, all of which contain a digit? I have a workaround for
my current project, but it would be nice to be able to use mixed
alphanumeric strings in this context.

Thanks in advance for any insight you can give into this question.

Using R 2.1.1 (downloaded binary) on Windows XP Pro, car version 1.0-17
(installed from CRAN via Windows GUI). Complete version information
below:

  version
  _
platform i386-pc-mingw32
arch i386
os   mingw32
system   i386, mingw32
status
major2
minor1.1
year 2005
month06
day  20
language R

  t(t( installed.packages()['car',] ))
  [,1]
Package  car
LibPath  C:/Programs/R/rw2011/library
Version  1.0-17
Priority NA
Bundle   NA
Contains NA
Depends  R (= 1.9.0)
Suggests MASS, nnet, leaps
Imports  NA
Built2.1.0


I subscribe to the help list in digest form, so would appreciate being
copied directly in addition to seeing responses sent to the list.

David Dailey
Shoreline, Washington, USA
[EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Unexpected behavior in PBSmapping package

2007-08-10 Thread D. Dailey
Using R 2.5.1 on Windows XP Professional, and PBSmapping package version 
2.51, I have encountered some behavior which puzzles me.  I am including 
the package's listed maintainer on this email but also seek the thoughts 
of the R-help community.

I have a set of EventData, which I want to plot as points, and to color 
the points according to some criterion.  It turns out that some of my 
points fall outside my desired plotting region.  It looks like this 
causes the PBSmapping functions plotPoints and addPoints to incorrectly 
deal with the color assignments.

Consider the following toy example:

### Begin Example ###

library( PBSmapping )

# Define some EventData
events - as.EventData( read.table( textConnection(
'EID X  Y   Color
1 494 1494 red
2 497 1497 blue
3 500 1500 green
4 503 1503 yellow' ), header=TRUE, strings=FALSE ),
proj='UTM', zone=10 )

par( mfrow=c(3,1) )

# Plot the events with plot limits large enough to show
# the full extent of all the symbols
plotPoints( events, pch=16, cex=5, col=events$Color,
   xlim=c(490,508), ylim=c(1490,1508), proj=TRUE )
with( events, text( X, Y, toupper( substr( Color, 1, 1 ) ),
   font=2, cex=2 ) )

# Normal plot extents; partial symbols cut off by edges
# of plotting region (as expected)
plotPoints( events, pch=16, cex=5, col=events$Color, proj=TRUE )
with( events, text( X, Y, toupper( substr( Color, 1, 1 ) ),
   font=2, cex=2 ) )

## Now use more-restrictive plot limits
plotPoints( events, pch=16, cex=5, col=events$Color,
   xlim=c(499,505), ylim=c(1499,1505), proj=TRUE )
with( events, text( X, Y, toupper( substr( Color, 1, 1 ) ),
   font=2, cex=2 ) )
# Note that symbols are plotted in the right places (note text labels)
# but colors are not as expected

### End example ###


For the moment, I have worked around this issue by using a with( 
events, points( ... ) ) construction, but this seems suboptimal; I 
would prefer to use addPoints (which exhibits the same problem as 
plotPoints does in the toy example above).  I would appreciate any 
insights those on the list might have.

Please include me directly on any reply to the list, as I am at least a 
couple weeks behind on reading the digested version of the list.  I see 
that there have been no mentions of the PBSmapping package even in the 
digests I have not yet read.

Session info:

  sessionInfo()
R version 2.5.1 (2007-06-27)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
States.1252;LC_MONETARY=English_United 
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics  grDevices utils datasets 
methods   base

other attached packages:
PBSmapping
 2.51



--David Dailey
Shoreline, Washington, USA

__
R-help@stat.math.ethz.ch 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.