cgenolin,

I am worried that your proposed lessons will teach the wrong message.
The goal of good R programming is to think of the matrix as the unit.
Loops are usually the wrong answer.

Your third example should not be taught as a loop.  The simplest way to do
that in R is by using the outer function.

outer(1:5, 1:5, `>=`)  ## simplest statement

ifelse(outer(1:5, 1:5, `>=`), "*", " ")  ## get the '*' in the right place

print(ifelse(outer(1:5, 1:5, `>=`), "*", " "), quote=FALSE)  ## suppress
the quotation marks
Vector, matrix, and array operations are the important concepts inside a
function.
Most base functions work directly on arrays.  for example
sin(seq(0,pi, length=9))

The apply family of functions are usually much clearer than loops.
Start with the examples in
?lapply


Rich
On Fri, Apr 20, 2012 at 10:05 AM, cgenolin <[email protected]> wrote:

> Thanks for your answer.
>
> Yes, it is quite different from what I am looking for which will be more
> something like :
>
> --- 8< -----
>
> Exercice 1: wrote a function that compute the surface of a rectangle
>
> Exercice 2: wrote a function that compute factorial n (whithout using the
> function factorial)
>
> Exercice 3: wrote a function, that given a n, will draw a triangle of "*".
> Example with n=5
>
> *
> **
> ***
> ****
> *****
>
> --- 8< -----
>
> The first exemple is about writing a (very) simple function and returning
> the result ; the second
> need the use of a loop. The third will need two loops (for a beginer).
>
> And so on, on various topic.
>
> Christophe
>
>  Are you familiar with R Inferno? This is a programming-oriented
>> tutorial for R by the statistician Patric Burns. He has generously
>> placed it as a pdf online for free
>> (http://www.burns-stat.com/**pages/Tutor/R_inferno.pdf<http://www.burns-stat.com/pages/Tutor/R_inferno.pdf>[4]);
>>  you could
>>
>> also
>> purchase a copy. Of course this will be more than just a few practice
>> exercises (a lot more, and actually, I'm not sure there are any
>> exercises but you can certainly follow along with the examples).
>> Nonetheless, it may still be right up your alley. There are other
>> resources for learning the programming side of R, but only a few that
>> are as good, and none other free, so far as I know. If this is really
>> different from what you're looking for, you may want to reply with more
>> detail.
>>
>> Hope that helps. -Jeff
>>
>> On 4/20/2012 7:41 AM, cgenolin wrote:
>>
>>  Hi the list, I am looking for some exercices for a PhD student that
>>> start to learn R. He already "read" some tutorial, but now he needs
>>> some practice. He does *not* need to learn any statistical tools ; he
>>> just needs to work on programmation concept. So I am looking for some
>>> exercice sheet that will, for example, focus on : - structuring the
>>> data (data.frame / list / matrix / ...) - using controle syntax (for /
>>> if / while / function) - reading data - ... Any link for this kind of
>>> material? Sincerely Christophe [[alternative HTML version deleted]]
>>> ______________________________**_________________
>>> [email protected] [1] mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-sig-teaching<https://stat.ethz.ch/mailman/listinfo/r-sig-teaching>[2]
>>>  ----- No
>>>
>> virus
>>
>>> found in this message. Checked by AVG - www.avg.com [3] Version:
>>>
>>> 2012.0.1913 / Virus Database: 2411/4948 - Release Date: 04/20/12
>>>
>>
>> ______________________________**_________________
>> [email protected] [5] mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-sig-teaching<https://stat.ethz.ch/mailman/listinfo/r-sig-teaching>[6]
>>
>
>
>
> Links:
> ------
> [1] mailto:R-sig-teaching@r-**project.org <[email protected]>
> [2] 
> https://stat.ethz.ch/mailman/**listinfo/r-sig-teaching<https://stat.ethz.ch/mailman/listinfo/r-sig-teaching>
> [3] http://www.avg.com
> [4] 
> http://www.burns-stat.com/**pages/Tutor/R_inferno.pdf<http://www.burns-stat.com/pages/Tutor/R_inferno.pdf>
> [5] mailto:R-sig-teaching@r-**project.org <[email protected]>
> [6] 
> https://stat.ethz.ch/mailman/**listinfo/r-sig-teaching<https://stat.ethz.ch/mailman/listinfo/r-sig-teaching>
>
>
> ______________________________**_________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/**listinfo/r-sig-teaching<https://stat.ethz.ch/mailman/listinfo/r-sig-teaching>
>

        [[alternative HTML version deleted]]

_______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-teaching

Reply via email to