[R] dealing with missing values
arun
smartpink111 at yahoo.com
Tue May 20 19:40:31 CEST 2014
Also, if the dataset is `dat1`
model.matrix(~X+Y,data=dat1)[,-1]
Xdf Xrd Yas Yeq
1 1 0 1 0
2 1 0 0 0
3 0 0 1 0
4 0 0 0 1
5 0 1 0 0
6 0 1 0 1
A.K.
On Tuesday, May 20, 2014 1:32 PM, arun <smartpink111 at yahoo.com> wrote:
Hi,
It is better to show the data using ?dput(). It is not clear whether your missing values are read as "" or NA in the dataset.
Also, assuming that the function is from library(ade4)
#1st case. NAs
dat <- structure(list(X = structure(c(1L, 1L, NA, NA, 2L, 2L), .Label = c("df",
"rd"), class = "factor"), Y = structure(c(1L, NA, 1L, 2L, NA,
2L), .Label = c("as", "eq"), class = "factor")), .Names = c("X",
"Y"), class = "data.frame", row.names = c(NA, -6L))
#2nd case ""
dat1 <- structure(list(X = structure(c(2L, 2L, 1L, 1L, 3L, 3L), .Label = c("",
"df", "rd"), class = "factor"), Y = structure(c(2L, 1L, 2L, 3L,
1L, 3L), .Label = c("", "as", "eq"), class = "factor")), .Names = c("X",
"Y"), class = "data.frame", row.names = c(NA, -6L))
library(ade4)
acm.disjonctif(dat)
# X.df X.rd Y.as Y.eq
#1 1 0 1 0
#2 1 0 0 0
#3 0 0 1 0
#4 0 0 0 1
#5 0 1 0 0
#6 0 1 0 1
acm.disjonctif(dat1)
# X. X.df X.rd Y. Y.as Y.eq
#1 0 1 0 0 1 0
#2 0 1 0 1 0 0
#3 1 0 0 0 1 0
#4 1 0 0 0 0 1
#5 0 0 1 1 0 0
#6 0 0 1 0 0 1
#It seems that your data is similar to dat1
dat1[dat1==''] <- NA
dat1 <- droplevels(dat1)
acm.disjonctif(dat1)
# X.df X.rd Y.as Y.eq
#1 1 0 1 0
#2 1 0 0 0
#3 0 0 1 0
#4 0 0 0 1
#5 0 1 0 0
#6 0 1 0 1
A.K.
I have missing values in my data:
X Y
df as
df
as
eq
rd
rd eq
I am using the function ' acm.disjonctif' in R. But this function considers the missing values as factor (it assigned 1's):
X. X.df X.rd Y. Y.as Y.eq
1 0 1 0 0 1 0
2 0 1 0 1 0 0
3 1 0 0 0 1 0
4 1 0 0 0 0 1
5 0 0 1 1 0 0
6 0 0 1 0 0 1
I want to use acm.disjonctif but I do not want to use the missing values (so columns X. and Y.) in this table. How can I solve this problem?
More information about the R-help
mailing list