[R] library(datasets)

David Winsemius dwinsemius at comcast.net
Sat Nov 20 00:45:26 CET 2010


On Nov 19, 2010, at 6:10 PM, Thomas Stewart wrote:

> You may want to consider using eurodist in matrix form.  As in,
>
> ED <- as.matrix(eurodist)
>
> Then you could manipulate the matrix using standard or homemade  
> functions,
> like this one:
>
> max.matrix <- function(A) {
>  column <- ceiling(which.max(A)/nrow(A))
>  row <- which.max(A) - (column-1)*nrow(A)
>  A[row,column,drop=FALSE]
>  }
>
> max.matrix(ED)
>
> which gives the following output:
>
>       Athens
> Lisbon   4532
>
> As for your other issue, using the matrix form also works:
>
> rowSums(ED)

Agree that matricization aids the task. Here's another approach:

 > which( as.matrix(eurodist) == max(as.matrix(eurodist)),
             arr.ind=TRUE)
        row col
Lisbon  12   1
Athens   1  12


>
> Hope that helps.
> -tgs
>
>
>
> On Fri, Nov 19, 2010 at 10:23 AM, lgpeco <badblueboy4 at gmail.com>  
> wrote:
>
>>
>> ## i have one question anouth this package..
>> library(datasets)
>> eurodist
>> ## if i type this i get max distance between european cities
>>> max(eurodist)
>> [1] 4532
>> ## but i would like get something like this: 4532 Gilbratar - Anthens
>> ## and another one..
>> ## if a live in barcelona and i would like travel in all cities
>> ## how can i get sum of all distance to other cities... i try
>> sapply(eurodist["Barcelona"], sum)
>> ## and rowSums(eurodist["Barcelona",]) and it doesn't working.. tnx  
>> for
>> helping ;)
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/library-datasets-tp3050497p3050497.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>
> 	[[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