Re: [R] Using functions/loops for repetitive commands

2011-05-06 Thread Gerrit Eichner
Hello, Derek, first of all, be very aware of what David Winsemius said; you are about to enter the area of unprincipled data-mining (as he called it) with its trap -- one of many -- of multiple testing. So, *if* you know what the consequences and possible remedies are, a purely R-syntactic

[R] Using functions/loops for repetitive commands

2011-05-05 Thread dereksloan
I still need to do some repetitive statistical analysis on some outcomes from a dataset. Take the following as an example; id sex hiv age famsize bmi resprate 1 M Pos 23 2 16 15 2 F Neg 24 5 18

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread Gerrit Eichner
Hello, Derek, see below. On Thu, 5 May 2011, dereksloan wrote: I still need to do some repetitive statistical analysis on some outcomes from a dataset. Take the following as an example; id sex hiv age famsize bmi resprate 1 M Pos 23 2

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread dereksloan
Your code may be untested but it works - also helping me slowly to start understanding how to write functions. Thank you. However I still have difficulty. I also have some categorical variables to analyse by age hiv status - i.e. my dataset expands to (for example); id sex hiv age

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread Shekhar
Hi Derek, You can accomplish your loop jobs by following means: (a) use for loop (b) use while loop (c) use lapply, tapply, or sapply. (i feel lapply is the elegant way ) ---For Loop- for loops are pretty simple to use and is almost similar to any other

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread David Winsemius
On May 5, 2011, at 10:01 AM, dereksloan wrote: Your code may be untested but it works - also helping me slowly to start understanding how to write functions. Thank you. However I still have difficulty. I also have some categorical variables to analyse by age hiv status - i.e. my dataset

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread dereksloan
Thanks David, I did notice that and I got his code to work using wilcox.test for the continuous variables. The problem is that when I tried to alter the code to do chisq.test on my categorical variables there is something wrong with the syntax and I don't know what. Derek -- View this message

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread David Winsemius
On May 5, 2011, at 1:08 PM, dereksloan wrote: Thanks David, I did notice that and I got his code to work using wilcox.test for the continuous variables. The problem is that when I tried to alter the code to do chisq.test on my categorical variables there is something wrong with the syntax

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread dereksloan
Thanks a lot, I understand what you say but I'm having problems - maybe with the syntax or the specific command. You are right - I have a dataframe to store the data and want to automate the analysis. i.e. I want do a chisq.test with to know if alcohol intake (Y/N) differs between sexes, then

Re: [R] Using functions/loops for repetitive commands

2011-05-05 Thread David Winsemius
On May 5, 2011, at 1:45 PM, dereksloan wrote: Thanks a lot, I understand what you say but I'm having problems - maybe with the syntax or the specific command. You are right - I have a dataframe to store the data and want to automate the analysis. i.e. I want do a chisq.test with to