Hi Marc, I figured out the problem, when I ran a glm model earlier, I used A
as it's name. Now the program is working.., a good lesson to learn. Thank
you so much for you help!

Yanyan 



-----Original Message-----
From: Marc Schwartz (via MN) [mailto:mschwartz@mn.rr.com] 
Sent: Monday, April 17, 2006 2:20 PM
To: Gong, Yanyan
Subject: RE: [R] help

On Mon, 2006-04-17 at 13:40 -0400, Gong, Yanyan wrote:
> Hi Marc,
> 
> I checked, A is a numeric field, here is my data frame:
> 
> `data.frame':   91 obs. of  4 variables: 
>  $ A: num  22.5 27.5 32.5 37.5 42.5 47.5 52.5 57.5 62.5 67.5 ... 
>  $ P: int  1970 1970 1970 1970 1970 1970 1970 1970 1970 1970 ... 
>  $ D: int  55 180 303 349 437 489 386 383 334 229 ... 
>  $ Y: int  1602127 1340887 1122499 1043250 1005940 926649 766054
> 700415 613063 537763 ...
> 
> But when I do "min(A)", I got "Error in min(..., na.rm = na.rm) :
> invalid 'mode' of argument". I checked mode(A), it says it is a 
> "list". I am sure A was created as a numeric variable, and the program 
> used to work. After I changed the working directory, I kept getting 
> problems. The weird thing is the following works:
> 
> sumzero_p<-((P-min(P))/5+1) - mean((P-min(P))/5+1)
> sumzero_c<-((cohort-min(cohort))/5+1) - mean((cohort-min(cohort))/5+1)
> 
> In which, p is numeric variable for period, cohort is another numeric 
> variable for birth year.
> 
> Hope this gives you a hint of my problem. Thanks very much!
> 
> Sincerely.
> 
> Yanyan

Yep...'A' is numeric, but it is a column in a data frame. You might want to
review An Introduction to R, specifically section 6 and forward regarding
the means by which one refers to columns in a data frame.

http://cran.r-project.org/doc/manuals/R-intro.html#Lists-and-data-frames

I would check to see which 'P' is being referred to in your code above.
Did you use:

attach(data.frame)

at some point?

If not, then 'P' is _not_ the P in your data frame, but some other locally
created 'P'. You can use:

ls()

to list the current objects that you have created.

If you don't want to use attach/detach, you can use:

data.frame$A

to refer to 'A'. Similar syntax for the other columns.

Also, remember that R is case sensitive, so:

p != P

If you elect to use attach(), be sure that you use the complementary
detach() as well. 

BTW, using 'data.frame' as the name for your data frame is bad, since it is
also the name of a function, data.frame().  In most cases, R will be able to
tell the difference, but you risk getting bitten by an occasion where it
cannot.

Lastly, while I don't mind helping, when replying to a post on the list,
please respond back to the list as well (ie. Reply to All), so that the
thread integrity is maintained to help others via the list archive and to
enable others to respond.

HTH,

Marc




This e-mail message (and any attachments) may contain confid...{{dropped}}


