I'm trying to "unpaste" a string of digits into a vector of integers (see
my earlier mail). The statement sapply(...) below works when I test it, but
when it is put into a function, it doesn't.
Any explanation?
Knut
-----------------
Dgts2Int <- function(Dgts)
{
sapply(1:nchar(Dgts),
function(i)
as.integer(substring(Dgts,i,i)))
}
DgtsRw <- "11011"
sapply(1:nchar(DgtsRw),
function(i)
as.integer(substring(DgtsRw,i,i)))
#
# result is:
#
# [1] 1 1 0 1 1
#
# - ok
#
Dgts2Int(DgtsRw)
#
# result is:
#
# Problem in FUN(...X.sub.i....): Object "Dgts" not found
# Use traceback() to see the call stack
#
Knut M. Wittkowski, PhD,DSc
------------------------------------------
The Rockefeller University, GCRC
1230 York Ave #121B, Box 322, NY,NY 10021
+1(212)327-7175, +1(212)327-8450 (Fax)
kmw@rockefeller.edu
http://www.rucares.org/statist/
|