Dear r-help, Could you help me to find a solution for this error: Il y a eu 50 avis ou plus (utilisez warnings() pour voir les 50 premiers)> warnings()Messages d'avis : 1: In if ((data[pa, k] == df[, j]) & (data[ch, k] == i)) { ... : la condition a une longueur > 1 et seul le premier élément est utilisé 2: In if ((data[pa, k] == df[, j]) & (data[ch, k] == i)) { ... : la condition a une longueur > 1 et seul le premier élément est utilisé ch=3 pa=c(1,2) r=2 t=4 nb=15 ni=array(0,c( r,t)) for ( i in 1:r){ for (j in 1:t ){ for (k in 1:nb){ if ( (data[pa,k]== df[,j]) & (data[ch,k]==i)){ ni[i,j]=ni[i,j]+1 } } } } Best Regards [[alternative HTML version deleted]]
Mohamed Lajnef
2010-Apr-30 09:10 UTC
[R] Find solution for an error in the condition of if
Dear Nuel, could you send the error messages in English please. Adds & between the two conditions and try again if ( (data[pa,k]== df[,j]) && (data[ch,k]==i)) Best M anderson nuel a ?crit :> Dear r-help, > > Could you help me to find a solution for this error: > > Il y a eu 50 avis ou plus (utilisez warnings() pour voir les 50 premiers) > > >> warnings() >> > Messages d'avis : > 1: In if ((data[pa, k] == df[, j]) & (data[ch, k] == i)) { ... : > la condition a une longueur > 1 et seul le premier ?l?ment est utilis? > 2: In if ((data[pa, k] == df[, j]) & (data[ch, k] == i)) { ... : > la condition a une longueur > 1 et seul le premier ?l?ment est utilis? > > > ch=3 > pa=c(1,2) > r=2 > t=4 > nb=15 > ni=array(0,c( r,t)) > > for ( i in 1:r){ > > for (j in 1:t ){ > > for (k in 1:nb){ > > if ( (data[pa,k]== df[,j]) & (data[ch,k]==i)){ > > ni[i,j]=ni[i,j]+1 > } > } > } > } > > Best Regards > > [[alternative HTML version deleted]] > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Mohamed Lajnef,IE INSERM U955 eq 15 P?le de Psychiatrie H?pital CHENEVIER 40, rue Mesly 94010 CRETEIL Cedex FRANCE Mohamed.lajnef at inserm.fr tel : 01 49 81 31 31 (poste 18470) Sec : 01 49 81 32 90 fax : 01 49 81 30 99
Duncan Murdoch
2010-Apr-30 09:20 UTC
[R] Find solution for an error in the condition of if
On 30/04/2010 4:19 AM, anderson nuel wrote:> Dear r-help, > > Could you help me to find a solution for this error: > > Il y a eu 50 avis ou plus (utilisez warnings() pour voir les 50 premiers) > > >> warnings() >> > Messages d'avis : > 1: In if ((data[pa, k] == df[, j]) & (data[ch, k] == i)) { ... : > la condition a une longueur > 1 et seul le premier ?l?ment est utilis? >It's saying that the condition has length > 1 and only the first element is used. This is probably coming from the first part of the test: data[pa,k] will be scalar, but df[,j] looks like a vector of every element in column j. The result is a vector with as many entries as you have rows in df. Only the first of them will be compared to data[pa, k]. Duncan Murdoch> 2: In if ((data[pa, k] == df[, j]) & (data[ch, k] == i)) { ... : > la condition a une longueur > 1 et seul le premier ?l?ment est utilis? > > > ch=3 > pa=c(1,2) > r=2 > t=4 > nb=15 > ni=array(0,c( r,t)) > > for ( i in 1:r){ > > for (j in 1:t ){ > > for (k in 1:nb){ > > if ( (data[pa,k]== df[,j]) & (data[ch,k]==i)){ > > ni[i,j]=ni[i,j]+1 > } > } > } > } > > Best Regards > > [[alternative HTML version deleted]] > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
> warnings()1: In if ((data[pa, k] == df[, j]) & (data[ch, k] == i)) { ... : the condition has length>1 ,and only the first element is used I add & between the two conditions..it solve the problem. But , it gives a>> false result. >> >> Best Regards >> > > >[[alternative HTML version deleted]]