Skip to content

Data frame of different sized lists in a function call

3 messages · Jonathan Greenberg, David Winsemius, Greg Snow

#
I'm hoping to get some "best practice" feedback for constructing a 
function call which takes an undefined set of DIFFERENT length vectors 
-- e.g. say we have two lists:

list1=c(1:10)
list2=c(2:4)

lists = data.frame(list1,list2) coerces those two to be the same length 
(recycling list2 to fill in the missing rows) -- what is a quick way of 
having each of those lists retain their original lengths?  my function 
ultimately should look like:


myfunction = function(lists) {

...

}

I'm hoping this can be done with a single line, so the user doesn't have 
to pre-construct the data.frame before running the function, if at all 
possible.

Thanks!

--j
#
On Jan 28, 2010, at 4:03 PM, Jonathan Greenberg wrote:

            
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
#
If you understand the differences between R lists and R vectors then this should be easy:
Now you can pass the single list of 2 different sized vectors to your function.  For more details on working with lists (and vectors and functions and ... ) read "An Introduction to R" which is worth a lot more than you pay for it.

Hope this helps,