You need to provide an 'str(yarn)' so we can see what the structure is. I don't know what the 'pcr' program is expecting, but it looks like from what you have provided that 'yarn' might be a dataframe and "X" is a vector. Look at the documentation for pcr and see what it expects.
On Mon, May 10, 2010 at 9:08 PM, Ravi Ramaswamy <raram...@gmail.com> wrote: > Jim - thanks. > > It worked, however pcr program is still not accepting it.... there is a > sample yarn data loaded and I am comparing. My data looks like this > > > X1 X2 X3 X4 X5 X6 X7 > X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 > 1Kalle 2.36038 2.35396 2.34772 2.34167 2.33587 2.33036 2.32517 2.32033 > 2.31583 2.31168 2.30791 2.30450 2.30150 2.29891 2.29680 2.29523 2.29421 > > and yarn data looks like this > > NIR.1 NIR.2 NIR.3 NIR.4 NIR.5 NIR.6 NIR.7 NIR.8 > NIR.9 NIR.10 NIR.11 NIR.12 NIR.13 NIR.14 NIR.15 NIR.16 NIR.17 > NIR.18 > 1 3.06630 3.08610 3.10790 3.09720 2.99790 2.82730 2.62330 2.40390 2.19310 > 2.00580 1.83790 1.69070 1.57770 1.50330 1.43810 1.33730 1.22060 1.14100 > > So, I thought I could convert X1 to X.1 and it would work. The names seem > different. Not sure how to make the change > > > names(yarn) > [1] "NIR" "density" "train" > > but > > > names(X) > [1] "X.1" "X.2" "X.3" "X.4" "X.5" "X.6" "X.7" "X.8" > "X.9" "X.10" "X.11" "X.12" "X.13" "X.14" "X.15" "X.16" "X.17" > "X.18" > > > On Mon, May 10, 2010 at 9:05 PM, jim holtman <jholt...@gmail.com> wrote: > >> Is this what you want: >> >> > x <- paste("X", 1:10, sep='') >> >> > x >> [1] "X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" "X10" >> > sub("X", "X.", x) >> [1] "X.1" "X.2" "X.3" "X.4" "X.5" "X.6" "X.7" "X.8" "X.9" "X.10" >> > >> >> >> On Mon, May 10, 2010 at 8:53 PM, Ravi Ramaswamy <raram...@gmail.com>wrote: >> >>> Hi - a newbie question, if someone can please help.... >>> >>> I want to change X1, X2,,.....to X.1 X.2 etc in the names below. I am >>> using >>> the Principal Component Regression function (pcr) and it seems to want it >>> this way >>> >>> > datap3.pcr <- pcr(water ~ X, 10, data = datap3, Validation ="cv") >>> Error in model.frame.default(formula = water ~ X, data = datap3) : >>> invalid type (list) for variable 'X' >>> >>> ---------- >>> >>> > names(X) >>> [1] "X1" "X2" "X3" "X4" "X5" "X6" "X7" "X8" "X9" "X10" >>> "X11" "X12" "X13" "X14" "X15" "X16" "X17" "X18" "X19" "X20" >>> [21] "X21" "X22" "X23" "X24" "X25" "X26" "X27" "X28" "X29" >>> "X30" >>> "X31" "X32" "X33" "X34" "X35" "X36" "X37" "X38" "X39" "X40" >>> [41] "X41" "X42" "X43" "X44" "X45" "X46" "X47" "X48" "X49" >>> "X50" >>> "X51" "X52" "X53" "X54" "X55" "X56" "X57" "X58" "X59" "X60" >>> [61] "X61" "X62" "X63" "X64" "X65" "X66" "X67" "X68" "X69" >>> "X70" >>> "X71" "X72" "X73" "X74" "X75" "X76" "X77" "X78" "X79" "X80" >>> [81] "X81" "X82" "X83" "X84" "X85" "X86" "X87" "X88" "X89" >>> "X90" >>> "X91" "X92" "X93" "X94" "X95" "X96" "X97" "X98" "X99" "X100" >>> > names(X)[1] >>> [1] "X1" >>> > for(i in 1:100){names(X)[i] <- "X.i"} >>> > names(X) >>> [1] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" >>> [25] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" >>> [49] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" >>> [73] "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" "X.i" >>> "X.i" >>> [97] "X.i" "X.i" "X.i" "X.i" >>> > for(i in 1:100){names(X)[i] <- X.i} >>> Error: object 'X.i' not found >>> > for(i in 1:100){names(X)[i] <- "X."i} >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >> >> -- >> Jim Holtman >> Cincinnati, OH >> +1 513 646 9390 >> >> What is the problem that you are trying to solve? >> > > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.