[R] [FORGED] Re: R lappy, sapply or mapply question
Rolf Turner
r.turner at auckland.ac.nz
Sat Oct 10 01:28:16 CEST 2015
On 10/10/15 10:56, Adams, Jean wrote:
> You were very close. Try this.
>
> df <- data.frame(x5=dailyrecord$a, x6 = dailyrecord$e, x7 = dailyrecord$f)
> apply(df, 1, function(row) fun3(list1, list2, as.list(row)))
There could in general be problems with this approach. The apply()
function works on *matrices* and if handed a data frame coerces it to a
matrix. This is (usually!) OK if all columns of the data frame are of
the same type, but the world could end if they are not. It is a good
idea to *start* with a matrix if a matrix is what is required. And do
not confuse data frames with matrices. They are very different animals.
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list