[R] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread Simon Kiss

Dear colleagues,
in the help archive there was a previous person who encountered a  
problem with the recode command in the car library. I'm not sure if  
that was solved, there was no posting to that effect, but I'm having  
the same problem.


I'm trying to recode a numeric variable with values from 0-100 into a  
binary variable with values (0,1).


The following command:

recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)

gets the following error message

Error in parse(text = range[[1]][1]) : unexpected end of input in  c(0

I tried it with a second numerical variable in the same data set, but  
get precisely the same error at precisely the same location in the  
command, i.e. the second colon.
As far as I can tell I have the most up-to-date version of car  
installed.

Any suggestions?
Yours, Simon Kiss

*
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

__
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.


Re: [R] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread Peter Ehlers

Get rid of the unnecessary c(...) construction:

 recode(green_2004_2$french, 50:100=0; 0:49.99=1)

 -Peter Ehlers

On 2010-04-14 1:56, Simon Kiss wrote:

Dear colleagues,
in the help archive there was a previous person who encountered a
problem with the recode command in the car library. I'm not sure if
that was solved, there was no posting to that effect, but I'm having the
same problem.

I'm trying to recode a numeric variable with values from 0-100 into a
binary variable with values (0,1).

The following command:

recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)

gets the following error message

Error in parse(text = range[[1]][1]) : unexpected end of input in  c(0

I tried it with a second numerical variable in the same data set, but
get precisely the same error at precisely the same location in the
command, i.e. the second colon.
As far as I can tell I have the most up-to-date version of car installed.
Any suggestions?
Yours, Simon Kiss

*
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

__
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.




--
Peter Ehlers
University of Calgary

__
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.


Re: [R] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread John Fox
Dear Simon,

The problem is that the recode specification is incorrect: In recode(),
colons mean ranges, and shouldn't appear within c(), which is used to list
values. See ?recode, and the following example:

 (green_2004_2 - data.frame(french=runif(10, 0, 100)))
  french
1  42.693517
2  18.063822
3  21.046906
4  17.045596
5   9.308359
6  30.018840
7  53.598261
8  17.739567
9  65.836818
10 37.727236
 recode(green_2004_2$french, 50:100=0; 0:49.99=1)
 [1] 1 1 1 1 1 1 0 1 0 1

BTW, 50:100=0; 0:50=1 will produce the same result -- again see ?recode.

Finally, it's generally a good idea to send a small reproducible example
with a question like this. What if there were really a data-dependent bug in
recode()?

I hope this helps,
 John


John Fox
Senator William McMaster 
  Professor of Social Statistics
Department of Sociology
McMaster University
Hamilton, Ontario, Canada
web: socserv.mcmaster.ca/jfox


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
 Behalf Of Simon Kiss
 Sent: April-14-10 3:56 AM
 To: r-help@r-project.org
 Subject: [R] Problem with recode -Error in parse(text = range[[1]][1]) :
 unexpected end of input in  c(0
 
 Dear colleagues,
 in the help archive there was a previous person who encountered a
 problem with the recode command in the car library. I'm not sure if
 that was solved, there was no posting to that effect, but I'm having
 the same problem.
 
 I'm trying to recode a numeric variable with values from 0-100 into a
 binary variable with values (0,1).
 
 The following command:
 
 recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)
 
 gets the following error message
 
 Error in parse(text = range[[1]][1]) : unexpected end of input in  c(0
 
 I tried it with a second numerical variable in the same data set, but
 get precisely the same error at precisely the same location in the
 command, i.e. the second colon.
 As far as I can tell I have the most up-to-date version of car
 installed.
 Any suggestions?
 Yours, Simon Kiss
 
 *
 Simon J. Kiss, PhD
 SSHRC and DAAD Post-Doctoral Fellow
 John F. Kennedy Institute of North America Studies
 Free University of Berlin
 Lansstraße 7-9
 14195 Berlin, Germany
 Cell: +49 (0)1525-300-2812,
 Web: http://www.jfki.fu-berlin.de/index.html
 
 __
 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.


Re: [R] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread David Winsemius


On Apr 14, 2010, at 2:56 AM, Simon Kiss wrote:


Dear colleagues,
in the help archive there was a previous person who encountered a  
problem with the recode command in the car library. I'm not sure  
if that was solved, there was no posting to that effect, but I'm  
having the same problem.


I'm trying to recode a numeric variable with values from 0-100 into  
a binary variable with values (0,1).


The following command:

recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)


Look at the last example in the recode help page:
recode(x, 1:2='A'; 3='B')
## [1] A A B A A B A A B
It appears to me that the c() function around your sequences may be  
part of the problem and I further wondered whether 0:49.99 can  
succeed. Generally the : operator expects integer arguments, but the  
help page is not clear in this area and it appears that recode has a  
different interpretation.

 require(car)
 recode(x, -Inf:0=-1; 0.01:Inf=1) # succeeds
--
David



gets the following error message

Error in parse(text = range[[1]][1]) : unexpected end of input in   
c(0


I tried it with a second numerical variable in the same data set,  
but get precisely the same error at precisely the same location in  
the command, i.e. the second colon.
As far as I can tell I have the most up-to-date version of car  
installed.

Any suggestions?
Yours, Simon Kiss

*
Simon J. Kiss, PhD
SSHRC and DAAD Post-Doctoral Fellow
John F. Kennedy Institute of North America Studies
Free University of Berlin
Lansstraße 7-9
14195 Berlin, Germany
Cell: +49 (0)1525-300-2812,
Web: http://www.jfki.fu-berlin.de/index.html

__
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.


Re: [R] Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in c(0

2010-04-14 Thread John Fox
Dear David,

Thank you for addressing this question, but I answered Simon's question in
an email I sent to the R help list a while ago: You can't mix : and c() in a
recode specification; : isn't the sequence operator in a recode
specification but rather represents a continuous range of values. Thus,
something like 0:49.99=1 is perfectly line, but c(0:49.99)=1 isn't.

Regards,
 John


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
 Behalf Of David Winsemius
 Sent: April-14-10 8:45 AM
 To: Simon Kiss
 Cc: r-help@r-project.org
 Subject: Re: [R] Problem with recode -Error in parse(text = range[[1]][1])
:
 unexpected end of input in  c(0
 
 
 On Apr 14, 2010, at 2:56 AM, Simon Kiss wrote:
 
  Dear colleagues,
  in the help archive there was a previous person who encountered a
  problem with the recode command in the car library. I'm not sure
  if that was solved, there was no posting to that effect, but I'm
  having the same problem.
 
  I'm trying to recode a numeric variable with values from 0-100 into
  a binary variable with values (0,1).
 
  The following command:
 
  recode(green_2004_2$french, c(50:100)=0; c(0:49.99)=1)
 
 Look at the last example in the recode help page:
 recode(x, 1:2='A'; 3='B')
 ## [1] A A B A A B A A B
 It appears to me that the c() function around your sequences may be
 part of the problem and I further wondered whether 0:49.99 can
 succeed. Generally the : operator expects integer arguments, but the
 help page is not clear in this area and it appears that recode has a
 different interpretation.
   require(car)
   recode(x, -Inf:0=-1; 0.01:Inf=1) # succeeds


 --
 David
 
 
  gets the following error message
 
  Error in parse(text = range[[1]][1]) : unexpected end of input in 
  c(0
 
  I tried it with a second numerical variable in the same data set,
  but get precisely the same error at precisely the same location in
  the command, i.e. the second colon.
  As far as I can tell I have the most up-to-date version of car
  installed.
  Any suggestions?
  Yours, Simon Kiss
 
  *
  Simon J. Kiss, PhD
  SSHRC and DAAD Post-Doctoral Fellow
  John F. Kennedy Institute of North America Studies
  Free University of Berlin
  Lansstraße 7-9
  14195 Berlin, Germany
  Cell: +49 (0)1525-300-2812,
  Web: http://www.jfki.fu-berlin.de/index.html
 
  __
  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.

__
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.