[R] Help required in using apply instead of for loop

2012-01-31 Thread arunkumar1111
Hi

I have  a function

y= x^2

min =10
max=20
increment=0.1

I want to find the value of y for the value of x between min and max by step
increment.

how to get the values using apply function instead of for loop

-
Thanks in Advance
Arun
--
View this message in context: 
http://r.789695.n4.nabble.com/Help-required-in-using-apply-instead-of-for-loop-tp4344350p4344350.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] Help required in using apply instead of for loop

2012-01-31 Thread Carlos Ortega
Hi,

You can do that even without apply():

v.v-seq(10,20, by=0.1)

y-v.v^2


But if you want it with apply...

apply(as.matrix(v.v), 1, function(x) x^2)


Regards,
Carlos Ortega
www.qualityexcellence.es



2012/1/31 arunkumar akpbond...@gmail.com

 Hi

 I have  a function

 y= x^2

 min =10
 max=20
 increment=0.1

 I want to find the value of y for the value of x between min and max by
 step
 increment.

 how to get the values using apply function instead of for loop

 -
 Thanks in Advance
Arun
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Help-required-in-using-apply-instead-of-for-loop-tp4344350p4344350.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.


[[alternative HTML version deleted]]

__
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.