I have a dataset (data1.csv) that contains some missing data (missing at random), I am creating a subset from this dataset (d1) such that only complete observations are retained in d2. I am using the ftable , as.data.frame function and creating a column p that represent the percentage of each combination.
d1 = read.csv("C:/Users/....../Data1.csv",header=T)
y x1 x2 x3
1 1 2 1 NA
2 0 2 NA 0
3 1 NA 1 1
4 0 3 1 0
5 0 2 0 NA
6 0 1 0 1
7 1 NA NA 1
8 1 3 0 1
9 1 2 0 0
10 0 3 0 NA
11 1 NA 0 1
12 1 3 NA 1
13 0 3 1 NA
14 0 NA 1 0
15 1 1 0 NA
16 0 1 NA 1
17 1 NA 0 NA
18 0 3 1 1
19 0 1 NA 0
20 0 NA 0 1
d2= d1[complete.cases(d1),]
d2
y x1 x2 x3
4 0 3 1 0
6 0 1 0 1
8 1 3 0 1
9 1 2 0 0
18 0 3 1 1
d3= ftable(d2)
d4=as.data.frame(d3)
d4
y x1 x2 x3 Freq p
1 0 1 0 0 0 0.0
2 1 1 0 0 0 0.0
3 0 2 0 0 0 0.0
4 1 2 0 0 1 0.2
5 0 3 0 0 0 0.0
6 1 3 0 0 0 0.0
7 0 1 1 0 0 0.0
8 1 1 1 0 0 0.0
9 0 2 1 0 0 0.0
10 1 2 1 0 0 0.0
11 0 3 1 0 1 0.2
12 1 3 1 0 0 0.0
13 0 1 0 1 1 0.2
14 1 1 0 1 0 0.0
15 0 2 0 1 0 0.0
16 1 2 0 1 0 0.0
17 0 3 0 1 0 0.0
18 1 3 0 1 1 0.2
19 0 1 1 1 0 0.0
20 1 1 1 1 0 0.0
21 0 2 1 1 0 0.0
22 1 2 1 1 0 0.0
23 0 3 1 1 1 0.2
24 1 3 1 1 0 0.0
The function ftable , as.data.frame works fine but the problem is I still see ALL these observations in the results (d4) which dosent make sense. I thought I got rid of this when i did complete.cases(d1)
So need help getting rid of missing values and doing frequency table only for these complete observations
y x1 x2 x3
4 0 3 1 0
6 0 1 0 1
8 1 3 0 1
9 1 2 0 0
18 0 3 1 1
read.csvwith thena.stringsparameter. - conjugateprior