[R] using apply to a data frame

David Winsemius dwinsemius at comcast.net
Fri Apr 8 04:21:43 CEST 2016


> On Apr 7, 2016, at 1:25 PM, John Sorkin <JSorkin at grecc.umaryland.edu> wrote:
> 
> 
> ‪‪I would like to apply a function, fract, to the columns of a
> dataframe. I tried the following 
> apply(data5NonEventEpochs,2,fract)
> but, no surprise it did not work as apply works on matrices not data
> frames.

As Bert pointed out your analsysis is incorrect. If `fract` is  function that takes a single vector then you should have gotten back a list or a matrix with as many entries or columns as the data5NonEventEpochs had columns.

So to do anything further, please post the output of dput(fract)

-- 
David.

> How can I apply a fuction to the columns of a data frame? (I
> can't covert data5NonEventsEpochs to a matrix as it contains character
> data).
> Thank you,
> John
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and
> Geriatric Medicine
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing) 
> 
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:16}}



More information about the R-help mailing list