Hi,

   I have a data frame with two variables x, y, both of which take values
in the set {1,2,3}. I'd like to count the frequency by the command "table",
but exclude the value "1" in variable x, but keep "1" in variable y. Is it
possible?  When I use "exclude", value 1 in both x and y are excluded.
Thanks,


> df <- data.frame(x = 1:3, y = 3:1, z = letters[1:3])
> table(df[,c("y","x")])
   x
y   1 2 3
  1 0 0 1
  2 0 1 0
  3 1 0 0
> table(df[,c("y","x")], exclude = 1)
   x
y   2 3
  2 1 0
  3 0 0
> table(df[,c("y","x")], exclude = c(NULL, 1))
   x
y   2 3
  2 1 0
  3 0 0
> table(df[,c("y","x")], exclude = c(1, NULL))
   x
y   2 3
  2 1 0
  3 0 0
> table(df[,c("y","x")], exclude = c(1, 0))
   x
y   2 3
  2 1 0
  3 0 0
> table(df[,c("y","x")], exclude = list(1 , NULL))
Error in as.vector(exclude, typeof(x)) :
  (list) object cannot be coerced to type 'integer'

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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