[R] sum in vector

2010-11-14 Thread lgpeco

hy guys i have one question :)

i have two vectors markets and price

market <- c(1, 5, 7, 9, 9, 6, 5, 4, 4, 3, 1, 2, 1)
price <- c(100, 20, 30, 10, 50, 23, 23, 33, 96, 6, 4, 38, 96)
i would like sum prices: market 1: (100+4+96), market 2: (38),..., market 9:
(10+50)
ao i would like get this result: (200, 38, ..., 60)
and i don't wanna use while, for loops... is there any other function to sum
these :)

tnx for helping ;)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/sum-in-vector-tp3041661p3041661.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] sum in vector

2010-11-14 Thread lgpeco

thx all for help

this function works fine
aggregate(price,list(market),sum) 
i also find another one sapply(x, function)
-- 
View this message in context: 
http://r.789695.n4.nabble.com/sum-in-vector-tp3041661p3042089.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] library(datasets)

2010-11-19 Thread lgpeco

## 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@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.