[R] Can't seem to get lapply to work.

Keith S Weintraub kw1958 at gmail.com
Fri Sep 26 05:25:44 CEST 2014


I have the following problem.

tstSet<-structure(list(corr = c(0.59, 0.62), term = c(7, 7), am = c("AmYes", 
"AmNo"), prem = c(19.5, 14.75)), .Names = c("corr", "term", "am", 
"prem"), out.attrs = structure(list(dim = structure(c(3L, 2L, 
2L, 41L), .Names = c("corr", "term", "am", "prem")), dimnames = structure(list(
    corr = c("corr=0.59", "corr=0.62", "corr=0.65"), term = c("term=5", 
    "term=7"), am = c("am=AmYes", "am=AmNo"), prem = c("prem=10.00", 
    "prem=10.25", "prem=10.50", "prem=10.75", "prem=11.00", "prem=11.25", 
    "prem=11.50", "prem=11.75", "prem=12.00", "prem=12.25", "prem=12.50", 
    "prem=12.75", "prem=13.00", "prem=13.25", "prem=13.50", "prem=13.75", 
    "prem=14.00", "prem=14.25", "prem=14.50", "prem=14.75", "prem=15.00", 
    "prem=15.25", "prem=15.50", "prem=15.75", "prem=16.00", "prem=16.25", 
    "prem=16.50", "prem=16.75", "prem=17.00", "prem=17.25", "prem=17.50", 
    "prem=17.75", "prem=18.00", "prem=18.25", "prem=18.50", "prem=18.75", 
    "prem=19.00", "prem=19.25", "prem=19.50", "prem=19.75", "prem=20.00"
    )), .Names = c("corr", "term", "am", "prem"))), .Names = c("dim", 
"dimnames")), row.names = c(460L, 239L), class = "data.frame")

> tstSet
    corr term    am  prem
460 0.59    7 AmYes 19.50
239 0.62    7  AmNo 14.75

A function:

twoRun<-function(aRow, inp) {
  aRow[["term"]] + inp

When I try the following:
lapply(tstSet, twoRun, 1)

I get the following error:
Error in aRow[["term"]] : subscript out of bounds

Any suggestions?

Thanks much for your time,


More information about the R-help mailing list