Hi,



I am very new to 'R' ("discovered" it about 2 months ago) and have been trying to teach myself the language using online guides, however I am not a programmer or statistician and so progress is slow.



As an exercise, I have been trying to generate the numbers 1 to 100 and replace multiples of 3 with the text "heads", multiples of 5 with the text "tails" and multiples of both 3 and 5 with the text "headstails".



So far I have managed to write the functions individually with:

> n=c(1:100)

> a=replace(n,n%%3==0,"heads")
> b=replace(n,n%%5==0,"tails")
> c=replace(n,n%%15==0,"headstails")



I would like to combine these functions into a single process to produce an output along the lines of:

1,2,"heads",4,"tails","heads",7,8,"heads","tails"... etc



I tried the following, without success:



> replace(n,c(n%%3==0,n%%5==0,n%%15==0),c("heads","tails,"headstails"))



As an 'R' novice I don't really have an idea of how I should approach this problem and unfortunately I have had problems trying to apply the answers given to other replace() and c() questions to my example.



I would be grateful if someone could point me in the right direction or provide a similar example of combining simple functions without just giving the answer away - i'd like to learn how to use 'R', rather than just be told the answer.



Regards,



Kile

	[[alternative HTML version deleted]]

