12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

You can’t use logical vectors or negative numbers as indices when using[[]]. You can use only a single value — either a (positive) number or anelement name.Using []You can use [] to extract either a single element or multiple elements from alist, but in this case the outcome is always a list. [] are more flexible than [[]],because you can use all the tricks you also use with vector and matrix indices. []can work with logical vectors and negative indices as well.So, if you want all elements of the list baskets.list except for the first one,you can use the following code:> baskets.list[-1][[1]][1] “season 2010-2011”Or if you want all elements of baskets.nlist where the name equals‘season’, you can use the following code:> baskets.nlist[names(baskets.nlist)==’season’]$season[1] “2010-2011”Note that, in both cases, the returned value is a list, even if it contains onlyone element. R simplifies arrays by default, but the same doesn’t count for lists.Changing the elements in listsMuch like all other objects we cover up to this point, lists aren’t static objects.You can change elements, add elements, and remove elements from them in apretty straightforward matter.Changing the value of elements

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!