Oh, another possibility is ?mapply, which I should have pointed out in my
previous reply. Sorry.

-- Bert


On Sun, Sep 1, 2013 at 8:30 AM, Bert Gunter <bgunter@gene.com> wrote:

> Rui et.al.:
>
> But apply will not work if the data frame has columns of different
> classes/types, as appears to be the case here. Viz, from ?apply:
>
> "If X is not an array but an object of a class with a non-null dim<http://127.0.0.1:12824/help/library/base/help/dim>
>  value (such as a data frame),apply attempts to coerce it to an array via
> as.matrix if it is two-dimensional (e.g., a data frame) or via as.array."
>
> Simply looping by rows (via for() ) appears to be the simplest and
> probably fastest solution. There are other ways via tapply() and friends,
> but these are also essentially loops and are likely to incur some
> additional overhead.
>
> All assuming I understand what the OP has requested, of course.
>
> Cheers,
>
> Bert
>
>
> On Sun, Sep 1, 2013 at 7:31 AM, Rui Barradas <ruipbarradas@sapo.pt> wrote:
>
>> Hello,
>>
>> Maybe you need apply, not lapply. It seems you want to apply() a function
>> to the first dimension of your data.frame, something like
>>
>> apply(dat, 1, fun)  #apply by rows
>>
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>> Em 01-09-2013 15:00, Ignacio Martinez escreveu:
>>
>>> I have a Data Frame that contains, between other things, the following
>>> fields: userX, Time1, Time2, Time3. The number of observations is 2000.
>>>
>>> I have a function that has as inputs userX, Time1, Time2, Time3 and
>>> return
>>> a data frame with 1 observation and 19 variables.
>>>
>>> I want to apply that function to all the observations of the first data
>>> frame to make a new data frame with 2000 observations and 19 variables.
>>>
>>> I thought about using lapply, but if I understand correctly, it only
>>> takes
>>> one variable.
>>>
>>> Can somebody point me in the right direction?
>>>
>>> Thanks!
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________**________________
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>> ______________________________**________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
>
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
>
>



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

	[[alternative HTML version deleted]]

