What exactly are you trying to do? If you want to know which position is
wrong, try :

if (sum(u$POSITION==0)>0) cat("WARNING:POSITION IS WRONG FOR
",which(u$POSITION==0),"\n")

or even :
wrong <- which(u$POSITION==0)
if(length(wrong)>0) cat("WARNING: POSITION IS WRONG
FOR",u$DESCRIPTION[wrong],"\n")

Gives you the exact location of wrong positions. If you do that, make sure
u$DESCRIPTION is a character vector and not a factor.

Cheers
Joris

On Wed, May 26, 2010 at 2:31 PM, arnaud Gaboury <arnaud.gabo...@gmail.com>wrote:

> Dear group,
>
> Here is my data frame:
>
> > dput(u)
> structure(list(DESCRIPTION = structure(c(2L, 5L, 6L, 7L, 9L,
> 11L, 12L, 15L, 14L, 16L, 1L, 10L, 3L, 4L, 13L, 8L, 17L), .Label = c("COFFEE
> C Jul/10",
> "COPPER May/10", "CORN Jul/10", "CORN May/10", "COTTON NO.2 Jul/10",
> "CRUDE OIL miNY May/10", "GOLD Jun/10", "HENRY HUB NATURAL GAS May/10",
> "ROBUSTA COFFEE (10) Jul/10", "SILVER May/10", "SOYBEANS Jul/10",
> "SPCL HIGH GRADE ZINC USD", "STANDARD LEAD USD", "SUGAR NO.11 Jul/10",
> "SUGAR NO.11 May/10", "WHEAT Jul/10", "WHEAT May/10"), class = "factor"),
>    PL = c(3500, -1874.99999999999, -2612.50000000003, -2169.99999999998,
>    -680, 425, 1025, 1008.00000000000, -3057.59999999999, 3212.5,
>    -1781.25000000001, -2265.0, 75, -387.5, 2950, 490.000000000013,
>    0), POSITION = c(-2, 3, 2, 2, 18, 3, -1, -1, 5, 5, 0, 0,
>    0, 0, 0, 0, 0)), .Names = c("DESCRIPTION", "PL", "POSITION"
> ), class = "data.frame", row.names = c(NA, -17L))
>
> I want to give a warning message if one of the element of the POSITION
> column is different from zero.
>
> I tried using mapply with some line like this :
>
> > mapply(if,u$POSITION,==0,print("WARNING:POSITIONS ARE WRONG",quote=F))
> But it seems it is not the correct way to pass the various arguments.
>
> Any help is appreciated
>
>
>
>
> ***************************
> Arnaud Gaboury
> Mobile: +41 79 392 79 56
> BBM: 255B488F
>
> ______________________________________________
> R-help@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.
>



-- 
Joris Meys
Statistical Consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

Coupure Links 653
B-9000 Gent

tel : +32 9 264 59 87
joris.m...@ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to