[R] How do you do this in R?

arun smartpink111 at yahoo.com
Tue Sep 17 04:40:48 CEST 2013



Hi,
No problem.
Please ?dput() your dataset.

dat<- read.table(text="
strategy region result
conservative desert 64.68427
moderate mountains 10.880242
moderate desert 48.72387
aggressive desert 34.37877
aggressive mountains 37.43783
moderate grassland 60.572490
aggressive forest 5.193187
aggressive grassland 15.527508",sep="",header=TRUE,stringsAsFactors=FALSE)

dat[with(dat,(result>mean(result)) & region!="grassland" ),]
#      strategy    region   result
#1 conservative    desert 64.68427
#3     moderate    desert 48.72387
#5   aggressive mountains 37.43783


dat$result[dat$region=="grassland"]<- NA


A.K.


Thank you so much for your help throughout these weeks! You've been such
a great help to me. I just have one more question sorry. 


When I try to get the mean I get this error 


In number 8 should I use subset or replace()? 


----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Monday, September 16, 2013 2:56 PM
Subject: Re: How do you do this in R?

Hi,
Try:
 sum(sapply(1:100,function(i) i^3+ 4*(i^2)))
#[1] 26855900
 169551560477066118158651749177/79632685831739040000 
#[1] 2129170437

sum(sapply(1:25,function(i) ((2^i)/i)+ ((3^i)/(i^2))))
#[1] 2129170437
A.K.



I have done this on myself using paper and I know the answer for A is 26,855,900 
B I got 169,551,560,477,066,118,158,651,749,177/79,632,685,831,739,040,000 

So sorry for the constant questions here.



More information about the R-help mailing list