1 year ago

#376701

test-img

Victor Nielsen

Why does this crosstabs change the result when I save it to csv?

Data example:

s2_nnormalefietsen_voor<- c("2+", "1", "0", "2+", "1", "0", "0", "1", "1", "0")
s2_nnormalefietsen_nu<- c("2+", "2+", "0", "2+", "1", "1", "0", "1", "0", "2+")

nnormalefietsen<- data.frame(s2_nnormalefietsen_voor, s2_nnormalefietsen_nu)

I have this code used to create a crosstab:

source("http://pcwww.liv.ac.uk/~william/R/crosstab.r")
crosstabs_nnormalefietsen <- crosstab(nnormalefietsen, row.vars = "s2_nnormalefietsen_voor", col.vars = "s2_nnormalefietsen_nu", type = "t")
crosstabs_nnormalefietsen <- crosstabs_nnormalefietsen$table/1961

write.csv(crosstabs_nnormalefietsen,"crosstabs_nnormalefietsen.csv")

This code:

crosstab(nnormalefietsen, row.vars = "s2_nnormalefietsen_voor", col.vars = "s2_nnormalefietsen_nu", type = "t")

Returns this:

                        s2_nnormalefietsen_nu      0      1     2+    Sum
s2_nnormalefietsen_voor                                                  
0                                               8.61   0.57   0.26   9.44
1                                               0.73  20.24   2.40  23.37
2+                                              0.63   1.77  64.79  67.19
Sum                                             9.96  22.59  67.45 100.00

But this code:

crosstabs_nnormalefietsen <- crosstab(nnormalefietsen, row.vars = "s2_nnormalefietsen_voor", col.vars = "s2_nnormalefietsen_nu", type = "t")
crosstabs_nnormalefietsen <- crosstabs_nnormalefietsen$table/1961

write.csv(crosstabs_nnormalefietsen,"crosstabs_nnormalefietsen.csv")

Returns this:

enter image description here

I understand that it might move the decimal point to points, but why do the actual numbers change?

r

datatable

export-to-csv

crosstab

0 Answers

Your Answer

Accepted video resources