Information Technology Reference
In-Depth Information
> dfrm <- data.frame(pred1, pred2, pred3, resp)
> dfrm
pred1 pred2 pred3 resp
1 -2.7528917 -1.40784130 AM 12.57715
2 -0.3626909 0.31286963 AM 21.02418
3 -1.0416039 -0.69685664 PM 18.94694
4 1.2666820 -1.27511434 PM 18.98153
5 0.7806372 -0.27292745 AM 19.59455
6 -1.0832624 0.73383339 AM 20.71605
7 -2.0883305 0.96816822 PM 22.70062
8 -0.7063653 -0.84476203 PM 18.40691
9 -0.8394022 0.31530793 PM 21.00930
10 -0.4966884 -0.08030948 AM 19.31253
Notice that data.frame takes the column names from your program variables. You can
override that default by supplying explicit column names:
> dfrm <- data.frame(p1=pred1, p2=pred2, p3=pred3, r=resp)
> dfrm
p1 p2 p3 r
1 -2.7528917 -1.40784130 AM 12.57715
2 -0.3626909 0.31286963 AM 21.02418
3 -1.0416039 -0.69685664 PM 18.94694
.
. (etc.)
.
Alternatively, your data may be organized into vectors, but those vectors are held in a
list instead of individual program variables, like this:
> lst <- list(p1=pred1, p2=pred2, p3=pred3, r=resp)
No problem. Use the as.data.frame function to create a data frame from the list of
vectors:
> as.data.frame(lst)
p1 p2 p3 r
1 -2.7528917 -1.40784130 AM 12.57715
2 -0.3626909 0.31286963 AM 21.02418
3 -1.0416039 -0.69685664 PM 18.94694
.
. (etc.)
.
1.10 Selecting Data Frame Columns by Position
Problem
You want to select columns from a data frame according to their position.
Solution
To select a single column, use this list operator:
 
Search WWH ::




Custom Search