[R] condition apply to elements of a data frame column
arnaud Gaboury
arnaud.gaboury at gmail.com
Wed May 26 14:37:39 CEST 2010
Oops, forgot to give a subject
> -----Original Message-----
> From: arnaud Gaboury [mailto:arnaud.gaboury at gmail.com]
> Sent: Wednesday, May 26, 2010 2:31 PM
> To: r-help at r-project.org
> Cc: 'arnaud Gaboury'
> Subject:
>
> 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
> ***************************
>
More information about the R-help
mailing list