s-news
[Top] [All Lists]

Re: as.character problem

To: Kyle Roberts <kroberts@unt.edu>
Subject: Re: as.character problem
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Wed, 10 Nov 2004 14:46:14 -0800
Cc: chuck@insightful.com, s-news@lists.biostat.wustl.edu
In-reply-to: <s192442d.063@gwia.unt.edu>
Organization: PDF Solutions, Inc.
References: <s192442d.063@gwia.unt.edu>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
Kyle,

I still cannot replicate this:

> z <- data.frame(x = rnorm(10), y = rnorm(10))
> x <- readline("Enter a formula:  ")
Enter a formula:  y ~ x
> x
[1] "y ~ x"
> lm(x, z)
Call:
lm(formula = x, data = z)

Coefficients:
 (Intercept)          x
  -0.4199697 -0.2295711

Degrees of freedom: 10 total; 8 residual
Residual standard error: 0.8161149
>
> version
Professional Edition Version 6.2.1  for Microsoft Windows : 2003
>

--sundar


Kyle Roberts wrote:
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


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