[R] data.frame error message

Liaw, Andy andy_liaw at merck.com
Wed Feb 23 12:23:18 CET 2005


> From: Nic Ellis
> 
> 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.

Seems like you still haven't told all that you did.  What is ppm.male.mark?
Is it an exact copy of `persist', or some subset?  Did you do any subsetting
after you create persiste.male?

If you get that error with plot(trt, ppmtrans), but not with plot(trt,
ppmtrans, data=whatever), then the first version is probably getting `trt'
and `ppmtrans' that you have lying around the global environment, which are
probably results from different subsetting operations (and thus having
different lengths).  Without more info, we can only guess.

One thing to keep in mind:  When using the formula interface, it will save
you some hair if all the variables used in the formula are in the data frame
supplied (and try to always supply the data frame).

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




More information about the R-help mailing list