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?

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

Reply via email to