s-news
[Top] [All Lists]

string of digits to vector of integers

To: s-news@lists.biostat.wustl.edu
Subject: string of digits to vector of integers
From: "Knut M. Wittkowski" <kmw@rockefeller.edu>
Date: Sat, 24 May 2003 20:20:26 -0400
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/


<Prev in Thread] Current Thread [Next in Thread>