[R] Help with IF command strings

arun smartpink111 at yahoo.com
Fri Jul 12 14:21:59 CEST 2013


Not sure I understand your question.
Suppose `data1` is your real data, but if the column names are different, change "V21", "V2" by those in the real data. Based on your initial post, the column names seemed to be the same.


What values would I substitute by real data.  I did everything the way 
you posted, and I got 3.8 as well.  So I'm curious what values I would 
change to get the mean for the actual data? 

----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: R help <r-help at r-project.org>
Sent: Thursday, July 11, 2013 9:21 PM
Subject: Re: Help with IF command strings

Try this:
dat1<- as.data.frame(matrix(sample(0:10,26*10,replace=TRUE),ncol=26))
#[1] 3.8
#[1] 3.8


I have data in 26 columns, I'm trying to get a mean for column 21 only for the participants that are either 0 or 1 in column 2. 

One of the commands I tried looked something like this 

mean(data1$V21, if(V2 = 1))   

So basically I need to have the program run a mean (and later 
other forms of analysis) on participants based on their condition. 
either 0 or 1. 

Help is greatly appreciated. 


More information about the R-help mailing list