[R] Dataframes in PLS package

Bjørn-Helge Mevik b.h.mevik at usit.uio.no
Tue Feb 21 15:54:08 CET 2012

westland <westland at uic.edu> writes:

> Here is what I have done:
> I read in an 10000 x 8 table of data, and assign the first four columns to
> matrix A and the second four to matrix B
> pls <-    read.table("C:/Users/Chris/Desktop/SEM Book/SEM Stat
> Example/Simple Header Data for SEM.csv",    header=TRUE, sep=",",
> na.strings="NA", dec=".", strip.white=TRUE)

The problem is here:

> A <- c(pls[1],pls[2],pls[3],pls[4])
> B <- c(pls[5],pls[6],pls[7],pls[8])

This creates lists A and B, not data frames.

Either use cbind() instead of c(), or simply say

A <- pls[,1:4]
B <- pls[,5:8]

The the rest should work.

Btw. it is probably a good idea to avoid single-character names for
variables.  Especially c and C, because they are names of functions in R.

Bjørn-Helge Mevik

More information about the R-help mailing list