[R] data.frame error message

Petr Pikal petr.pikal at precheza.cz
Wed Feb 23 14:23:54 CET 2005


Hi Nic

Be careful with variables with same names in your environment as 
variables in data.frame. If you have a variable with the same name 
e.g. ppmtrans in data frame and in environment, your commands use 
variable from environment. So probably trt is from data frame and 
ppmtrans from environment.

See what ls() will show you.

In models you can specify data=your.data.frame argument and all 
variables in formula are preferably used from this data frame, if I 
am not mistaken.

Cheers
Petr



On 23 Feb 2005 at 5:42, Nic Ellis wrote:

> At 09:47 PM 2/22/2005 -0500, Liaw, Andy wrote:
> >Following the suggestions in the Posting Guide would help us to help
> >you much better.
> >
> >What command(s) did you use to get the data into 
> >R?   read.table("C:/.../persist.dat",col.names=c("a","b",etc."))
> 
> 
> >What does the `.dat' file look like?  Itn was created in Word, as a
> >plain text file.
> 
> 6000 24 female 0.0014 1.4 1 3.47 0.25 2478.57
> 6000 168 female 0.0014 1.4 1 0.73 0.05 521.43
> 6000 96 female 0.0014 1.4 1 0.96 0.07 685.71
> 6000 168 female 0.0014 1.4 1 1.36 0.10 971.43
> 6000 24 female 0.0014 1.4 1 2.69 0.19 1921.43
> 6000 96 female 0.0014 1.4 1 0.76 0.05 542.86...
> 
> >What are `x' and `y'?  'x' is "trt" and 'y' is "ppmtrans".  I did
> >subset commands to find all the males with "ppmsamp"
> above a certain value.
> >
> 
> persist[1:5,]
>     dose     trt    sex      massg   massmg vol  ppm  perc ppmsamp 1 
> 6000  24     female 0.0014    1.4         1   3.47  0.25 2478.57 2 
> 6000  168  female 0.0014    1.4          1   0.73  0.05  521.43 3 
> 6000  96    female 0.0014    1.4          1   0.96  0.07  685.71 4 
> 6000  168  female 0.0014    1.4          1   1.36  0.10  971.43 5 
> 6000  24    female 0.0014    1.4          1    2.69  0.19 1921.43
> ...subsetting commands... ppmtrans<-sqrt(sqrt(ppm.male.mark$ppmsamp))
>  > persist.male<-cbind(ppm.male.mark,ppmtrans)
>  > persist.male[1:5,]
>     dose trt  sex  massg massmg vol  ppm perc ppmsamp ppmtrans
> 27 6000  96 male 0.0012    1.2   1 1.82 0.15 1516.67 6.240549
> 55 6000 168 male 0.0012    1.2   1 0.90 0.08  750.00 5.233176
> 70 6000 168 male 0.0012    1.2   1 1.97 0.16 1641.67 6.365338
> 76 6000  96 male 0.0012    1.2   1 4.02 0.34 3350.00 7.607837
> 83 6000 168 male 0.0012    1.2   1 1.26 0.11 1050.00 5.692425
>  > plot(trt,ppmtrans)
> Error in model.frame(formula, rownames, variables, varnames, extras,
> extranames,  :
>          variable lengths differ
> 
> After my initial post, I found that if I specified the data set in the
> plot arguments, I could generate a boxplot.  I then performed ANOVA on
> the response after creating factor levels for "trt", and generated a
> stripchart showing the data in each of the three trts.  But for future
> reference, if I need to do linear regression with a similar data set,
> I'd like to know what is happening.
> 
> Thank you--
> 
> NH Ellis
> 
> 
> 
>  [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list