Skip to content
Prev 198844 / 398503 Next

convert list to numeric

An example will help show the difference between single vs. double brackets.

## xl is  a list with three elements
$a
[1] 1 2 3

$b
[1] 2 3 4 5 6 7

$c
[1] "X" "Y"
## with single brackets, we get a subset. A subset of a list is still a list
$a
[1] 1 2 3

## extract the first element of xl, as itself, whatever it is
[1] 1 2 3

## with single brackets, we get a subset. In the next example the subset
## consists of the first and third elements of xl, i.e., a list 
having two elements
$a
[1] 1 2 3

$c
[1] "X" "Y"


## Similarly for data frames, and note how the formatting is 
different when the object
## is printed to the screen
a b c
1 1 2 X
2 2 3 Y
3 3 4 Z
[1] "data.frame"
b
1 2
2 3
3 4
[1] "data.frame"
[1] 2 3 4
[1] "integer"
At 6:22 AM -0800 11/2/09, dadrivr wrote: