cgenolin | 20 Apr 2012 13:41
Picon
Favicon

R exercices


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]]

(Continue reading)

Jeff Laux | 20 Apr 2012 15:30
Picon

Re: R exercices

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); 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 / ...)
(Continue reading)

Paula Young | 20 Apr 2012 15:55
Favicon

Re: R exercices

To echo what was just posted, the R Inferno document is excellent and I
think that, even though it may not be exactly what you are looking for to
help your student, that both you and your student will learn a great deal
about R (and S) as a programming environment by working through the
examples.

PGY
---
Dr. Paula Grafton Young
Associate Professor of Mathematics
Chair, Curriculum Committee, 2011 - 2013
Chair, Strategic Planning Steering Committee, 2012 - 2013
paula.young <at> salem.edu
336.721.2747 (O)
336.721.2653 (F)

 <http://www.facebook.com/SalemCollege>
<http://www.twitter.com/SalemCollege>

On Fri, Apr 20, 2012 at 9:30 AM, Jeff Laux <jefflaux <at> gmail.com> wrote:

> 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>);
> 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
(Continue reading)

cgenolin | 20 Apr 2012 16:05
Picon
Favicon

Re: R exercices

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

(Continue reading)

R. Michael Weylandt | 20 Apr 2012 16:45
Picon

Re: R exercices

R is in the broad family of functional languages -- if your student is
on board with the statistical capabilities of R, he might benefit from
looking at one of the classic tutorials for those while doing the
exercises in R. SICP is a classic, but the syntax doesn't match: maybe
the python version works
http://www-inst.eecs.berkeley.edu/~cs61a/sp12/book/index.html :
alternatively, think Python or think Complexity (both online) provide
another (less difficult) exposition. However, take these options with
a grain of salt: if your student learns R this way, he'll get some bad
R habits that will take a long time to break: I'd highly advise
against any solution that suggests he do the

*
**
***

puzzle with nested loops: performance in later programming assignments
will be terrible. Better to learn good habits now: lapply(1:n,
function(x) cat(rep("*", n), "\n")

Alternatively, working through something like Project Euler in R will
require a little more self-starting, but might be more rewarding after
he masters the basics of syntax. (just what's given in a first read
through the standard intro to R document)

Finally, Matloff's Art of R programming is probably exactly what
you're looking for, but isn't free.

Hope this helps, (and my strong advice is options 2 or 3)

(Continue reading)

R. Michael Weylandt | 20 Apr 2012 16:46
Picon

Re: R exercices

Sorry typo -- lapply(1:n, function(x) cat(rep("*",x),"\n"))

M

On Fri, Apr 20, 2012 at 10:45 AM, R. Michael Weylandt
<michael.weylandt <at> gmail.com> wrote:
> R is in the broad family of functional languages -- if your student is
> on board with the statistical capabilities of R, he might benefit from
> looking at one of the classic tutorials for those while doing the
> exercises in R. SICP is a classic, but the syntax doesn't match: maybe
> the python version works
> http://www-inst.eecs.berkeley.edu/~cs61a/sp12/book/index.html :
> alternatively, think Python or think Complexity (both online) provide
> another (less difficult) exposition. However, take these options with
> a grain of salt: if your student learns R this way, he'll get some bad
> R habits that will take a long time to break: I'd highly advise
> against any solution that suggests he do the
>
> *
> **
> ***
>
> puzzle with nested loops: performance in later programming assignments
> will be terrible. Better to learn good habits now: lapply(1:n,
> function(x) cat(rep("*", n), "\n")
>
> Alternatively, working through something like Project Euler in R will
> require a little more self-starting, but might be more rewarding after
> he masters the basics of syntax. (just what's given in a first read
> through the standard intro to R document)
(Continue reading)

Richard M. Heiberger | 22 Apr 2012 06:15
Picon
Favicon

Re: R exercices

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 <cgenolin <at> u-paris10.fr> wrote:

> Thanks for your answer.
>
> Yes, it is quite different from what I am looking for which will be more
(Continue reading)

cgenolin | 22 Apr 2012 11:39
Picon
Favicon

Re: R exercices


Well, you are perfectly right. It is why in can not write the
lessons myself: I have a C++ way of thinking, and I would like to not
transmit it to my student. 

>From the responses I get, it is clear that
there isn't a book that presents such exercises. But I was more hopping
to find my happiness in some kind of "classical exercises sheet" that
teachers write for their student. I myself write 11 exercise sheet for
learning the use of the basic structure and the basic test (lesson 1: R
gui interface; lesson 2: reading a file and data basic structure ;
lesson 3: chi square and t test,...) 

Unfortunately, my exercise's
sheets (on my web site) are about "R test". Does any R teachers have
this kind of exercise sheet, but for "learning R basics"? 

Christophe

> 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 
>
(Continue reading)

Nilesh Gupta | 22 Apr 2012 05:43
Picon

Re: R exercices

Christophe

I learnt by first language(C) using programming structures similar to the
ones you have mentioned, though i do not see any such programming examples
in R books that I have read. The book which comes closest to teaching R
like i learnt C is Norman Matloff. the art of R programming. The
arrangement of the book is similar to how a normal coding book is written (
a chapter on elementary datatypes and how to declare them, followed by
chapters on loops,controls, other syntax and then followed by more advanced
datatypes(list and frame in case of R).
However even this book does not have the type of examples that you have
mentioned. However if the introductory learner can set up an R environment
and if he works through the solved examples given in the book by actually
typing them in R, that may solve your purpose.

Hope this helps

Nilesh
Forwarded Message
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)
(Continue reading)

nf grinberg | 18 Aug 2012 22:47
Picon

Re: R exercices

cgenolin <cgenolin <at> u-paris10.fr> writes:

> 
> 
> 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 
(Continue reading)

Robert Baer | 20 Aug 2012 18:30
Gravatar

Re: R exercices

You could have him work through Norman Matloff's book, "The Art of R 
Programming" which covers the things you list.

Rob

On 8/18/2012 3:47 PM, nf grinberg wrote:
> cgenolin <cgenolin <at> u-paris10.fr> writes:
>
>>
>> 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
(Continue reading)

Jeff Laux | 20 Aug 2012 18:37
Picon

Re: R exercices

Matloff's book is very good, but  a critical shortcoming is that it does 
not include exercises, so it may not meet the stated requirements.

On 8/20/2012 12:30 PM, Robert Baer wrote:
> You could have him work through Norman Matloff's book, "The Art of R 
> Programming" which covers the things you list.
>
> Rob
>
>
> On 8/18/2012 3:47 PM, nf grinberg wrote:
>> cgenolin <cgenolin <at> u-paris10.fr> writes:
>>
>>>
>>> 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)
(Continue reading)

Robert Baer | 20 Aug 2012 18:52
Gravatar

Re: R exercices

On 8/20/2012 11:37 AM, Jeff Laux wrote:
> Matloff's book is very good, but  a critical shortcoming is that it 
> does not include exercises, so it may not meet the stated requirements.
Point well taken.  The lack of Chapter-end exercises makes this book not 
work well for a classroom environment, but the OP did say, "... for a 
PhD student ...", and the book is full of exercises that the author 
takes readers through. This collection of  exemplars might be perfect 
for  self-study by a PhD student looking to move on to solve his own 
problems.

Rob
>
>
> On 8/20/2012 12:30 PM, Robert Baer wrote:
>> You could have him work through Norman Matloff's book, "The Art of R 
>> Programming" which covers the things you list.
>>
>> Rob
>>
>>
>> On 8/18/2012 3:47 PM, nf grinberg wrote:
>>> cgenolin <cgenolin <at> u-paris10.fr> writes:
>>>
>>>>
>>>> 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.
(Continue reading)

Jeff Laux | 20 Aug 2012 19:10
Picon

Re: R exercices

I agree with you, and I really don't want to get into an argument over 
the email list, but note that it can be difficult to follow along with 
Matloff's examples because the data he's using aren't posted anywhere 
(at least that I could find, if someone else knows where they are please 
respond).  Again, I think Matloff's book is very good, and I got a lot 
out of reading it.  You can try some of the examples.  I do recommend it 
to people.  It may well be a good recommendation for this individual, in 
addition to something else that provides exercises that he can practice on.

On 8/20/2012 12:52 PM, Robert Baer wrote:
> On 8/20/2012 11:37 AM, Jeff Laux wrote:
>> Matloff's book is very good, but  a critical shortcoming is that it 
>> does not include exercises, so it may not meet the stated requirements.
> Point well taken.  The lack of Chapter-end exercises makes this book 
> not work well for a classroom environment, but the OP did say, "... 
> for a PhD student ...", and the book is full of exercises that the 
> author takes readers through. This collection of  exemplars might be 
> perfect for  self-study by a PhD student looking to move on to solve 
> his own problems.
>
> Rob
>>
>>
>> On 8/20/2012 12:30 PM, Robert Baer wrote:
>>> You could have him work through Norman Matloff's book, "The Art of R 
>>> Programming" which covers the things you list.
>>>
>>> Rob
>>>
>>>
(Continue reading)

Gabor Grothendieck | 20 Aug 2012 19:28
Picon

Re: R exercices

On Mon, Aug 20, 2012 at 1:10 PM, Jeff Laux <jefflaux <at> gmail.com> wrote:
> I agree with you, and I really don't want to get into an argument over the
> email list, but note that it can be difficult to follow along with Matloff's
> examples because the data he's using aren't posted anywhere (at least that I
> could find, if someone else knows where they are please respond).  Again, I
> think Matloff's book is very good, and I got a lot out of reading it.  You
> can try some of the examples.  I do recommend it to people.  It may well be
> a good recommendation for this individual, in addition to something else
> that provides exercises that he can practice on.

The data is on the book's page on the publisher's site.

--

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

Jeff Laux | 20 Aug 2012 19:41
Picon

Re: R exercices

Thanks!  So they are 
(http://nostarch.com/download/code/artofr_data.zip).  In which case, the 
book may be a better fit for this situation.

On 8/20/2012 1:28 PM, Gabor Grothendieck wrote:
> On Mon, Aug 20, 2012 at 1:10 PM, Jeff Laux <jefflaux <at> gmail.com> wrote:
>> I agree with you, and I really don't want to get into an argument over the
>> email list, but note that it can be difficult to follow along with Matloff's
>> examples because the data he's using aren't posted anywhere (at least that I
>> could find, if someone else knows where they are please respond).  Again, I
>> think Matloff's book is very good, and I got a lot out of reading it.  You
>> can try some of the examples.  I do recommend it to people.  It may well be
>> a good recommendation for this individual, in addition to something else
>> that provides exercises that he can practice on.
> The data is on the book's page on the publisher's site.
>


Gmane