Assignment
To assign a value to a variable, use the assignment operator<-
like this
x <- 23
Vectors
The basic R data type is not a single number, but a "vector", which is what R calls a sequence of numbers. R uses vectors to represent whole data sets. The R functionc collects numbers into a single
vector object, for example,
x <- c(2,4,11,17) creates a vector of length 4
Data Frames
Often data sets consist of several vectors of the same length, which consist of measurements of different variables on the same individuals. R has a data structure that caters to this situation called a data frame. Ifx, y, and z
are vectors of the same length, then fred <- data.frame(x, y, z)很好的介紹
http://data.princeton.edu/R/linearModels.html
------------------------------------------------------------------
par(mfrow=c(2,2))
fpe <- read.table("effort.dat")
attach(fpe)
summary(fpe)
mean(effort)
cor(effort,change)
lmfit = lm( change ~ setting + effort )
lmfit
summary(lmfit)
anova(lmfit)
plot(lmfit)
fitted(lmfit)
coef(lmfit)
residuals(lmfit)
names(lmfit)
#png("cor2.png", height=600, width=600)
#plot(effort, change, pch=21, bg="gold")
#title("Scatterplot of Change by Effort", col.main="#3366CC")
# dev.off()
沒有留言:
張貼留言