Friday, November 11, 2016

R: list vs. (c)ombine

list vs. (c)ombine

(Lists can hold different types of objects; keeps them distinct.)




> mylist = list(x=1:5, y=c("a", "b", "c"), z=c(T,F,T))
> mylist
$x
[1] 1 2 3 4 5

$y
[1] "a" "b" "c"

$z
[1]  TRUE FALSE  TRUE

> mycombine = c(x=1:5, y=c("a", "b", "c"), z=c(T,F,T))
> mycombine
     x1      x2      x3      x4      x5      y1 
    "1"     "2"     "3"     "4"     "5"     "a" 
     y2      y3      z1      z2      z3 
    "b"     "c"  "TRUE" "FALSE"  "TRUE" 


 
 

Wednesday, November 9, 2016

R: assign function

This will come in handy someday...


    x = "y"
    assign(x, c(3:6))



The result is a variable x with value "y", and a vector y with values int[1:4] 3 4 5 6