[R] Confused: Inconsistent result?
David Winsemius
dwinsemius at comcast.net
Mon Feb 20 16:17:00 CET 2012
On Feb 20, 2012, at 10:07 AM, Ajay Askoolum wrote:
> This is copy & paste from my session:
>
>> xyz<-as.vector(c(ls(),as.matrix(lapply(ls(),class))))
>> dim(xyz)<-c(length(xyz)/2,2)
>>
>> allobj<-function(){
> + xyz<-as.vector(c(ls(),as.matrix(lapply(ls(),class))));
> + dim(xyz)<-c(length(xyz)/2,2);
> + return(xyz)
> + }
>> xyz
> [,1] [,2]
> [1,] "a" "character"
> [2,] "aa" "character"
> [3,] "abc" "character"
> [4,] "AirPassengers" "character"
> [5,] "allobj" "character"
> [6,] "allObjects" "character"
> [7,] "allObjects2" "character"
> [8,] "arrayFromAPL" "character"
> [9,] "classes" "character"
> [10,] "myCharVector" "character"
> [11,] "myDateVector" "character"
> [12,] "myNumericVector" "character"
> [13,] "newArrayFromAPL" "character"
> [14,] "obj" "character"
> [15,] "objClass" "character"
> [16,] "x" "character"
> [17,] "xyz" "character"
> [18,] "y" "character"
>> allobj()
> [,1] [,2]
>>
>
> As far as I can see, the function allobj has the same expressions as
> those executed from the command line. Why are the results different?
The ls function looks only in the local environment if not supplied
with specific directions about where to look.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list