s-news
[Top] [All Lists]

Re: as.character problem

To: <chuck@insightful.com>, <s-news@lists.biostat.wustl.edu>
Subject: Re: as.character problem
From: "Kyle Roberts" <kroberts@unt.edu>
Date: Wed, 10 Nov 2004 16:38:00 -0600
Chuck and others,

Here is an example of what I am trying to do - I want the user to enter
in a formula into the readline command and then use that formula in a
function later such that:

> x <- readline("Enter a formula:  ")
Enter a formula:  MATHACH~VISUAL+GENDER
> x
[1] "MATHACH~VISUAL+GENDER"

But then when I try something like:
> lm(x, data)

I get the following error:
1 missing values generated coercing from character to numeric in:
as.numeric(x)

Any suggestions?????

*****************************************************
J. Kyle Roberts, Ph.D.
Assistant Professor of Educational Research
University of North Texas
P.O.Box 311335
Denton, TX   76203-1335
voice - 940-369-7168
fax - 940-565-2185
kroberts@unt.edu
*****************************************************

>>> "Chuck Taylor" <chuck@insightful.com> 11/10/2004 3:51:09 PM >>>
Kyle,

I would be interested to see what you did to get that error message.  
I tried to reproduce it, but I don't get that error.  And what does 
this have to do with as.character()?

> x <- readline("Enter a number:  ")
Enter a number:  12.5
> x
[1] "12.5"
> as.numeric(x)
[1] 12.5
> as.integer(x)
[1] 12
> 
> 
> x <- readline("Enter a number:  ")
Enter a number:  abc
> x
[1] "abc"
> as.numeric(x)
[1] NA
Warning messages:
    1 missing values generated coercing from character to numeric in:
as.numeric(x)
> 

--
Chuck

Chuck Taylor
Sr. Quality Assurance Engineer
Insightful Corporation
Seattle, WA, USA
 

> -----Original Message-----
> From: Kyle Roberts [mailto:kroberts@unt.edu] 
> Sent: Wednesday, November 10, 2004 11:35 AM
> To: s-news@lists.biostat.wustl.edu 
> Subject: [S] as.character problem
> 
> 
> Dear All,
> 
> I am trying to make a more user-friendly program and am using the
> readline command to accept information from the user.  I then want
to
> use this information in a function, but keep getting an error
message
> saying "Invalid data for conversion from character to integer" when
I
> try and use their information from the readline command in another
> function.  Is there a quick solution to this??
> 
> Thanks,
> Kyle
> 
> *****************************************************
> J. Kyle Roberts, Ph.D.
> Assistant Professor of Educational Research
> University of North Texas
> P.O.Box 311335
> Denton, TX   76203-1335
> voice - 940-369-7168
> fax - 940-565-2185
> kroberts@unt.edu 
> *****************************************************
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu
with
> the BODY of the message:  unsubscribe s-news
> 

<Prev in Thread] Current Thread [Next in Thread>