I have a data.frame called tmp. Here is the summary:
> summary(tmp)
Organization Advance Monthly Sales Other Homeownership Rate
Length:2460 Min. : 0 Min. : 0 Min. : 0
Class :character 1st Qu.: 0 1st Qu.: 0 1st Qu.: 0
Mode :character Median : 0 Median : 2 Median : 0
Mean : 1 Mean : 53 Mean : 3
3rd Qu.: 0 3rd Qu.: 14 3rd Qu.: 0
Max. :637 Max. :34622 Max. :3272
New Residential Construction New Residential Sales Construction Spending
Min. : 0 Min. : 0 Min. : 0
1st Qu.: 0 1st Qu.: 0 1st Qu.: 0
Median : 0 Median : 0 Median : 0
Mean : 10 Mean : 1 Mean : 83
3rd Qu.: 0 3rd Qu.: 0 3rd Qu.: 0
Max. :9078 Max. :1856 Max. :60630
U.S. International Manufacturing and Trade Advance Report on Durable Goods
Min. : 0 Min. : 0 Min. : 0
1st Qu.: 0 1st Qu.: 0 1st Qu.: 0
Median : 0 Median : 0 Median : 0
Mean : 18 Mean : 0 Mean : 2
3rd Qu.: 3 3rd Qu.: 0 3rd Qu.: 0
Max. :11992 Max. :874 Max. :4785
Quarterly Financial Report Advance U.S. Intl Trades Monthly Wholesale Trade
Min. : 0 Min. : 0 Min. : 0
1st Qu.: 0 1st Qu.: 0 1st Qu.: 0
Median : 0 Median : 0 Median : 0
Mean : 0 Mean : 0 Mean : 0
3rd Qu.: 0 3rd Qu.: 0 3rd Qu.: 0
Max. :478 Max. :849 Max. :697
Quarterly Services Survey Business Formation Statistics Total
Min. : 0 Min. : 0 Min. :0
1st Qu.: 0 1st Qu.: 0 1st Qu.:0
Median : 0 Median : 0 Median :0
Mean : 0 Mean : 0 Mean :0
3rd Qu.: 0 3rd Qu.: 0 3rd Qu.:0
Max. :423 Max. :233 Max. :0
I'm using this command to create a column "N"
tmp$Total <- rowSums(tmp[, -1])
And then I see this output:
> head(tmp, 1)
Organization Advance Monthly Sales Other
1 VeriSign Infrastructure & Operations 1 0
Homeownership Rate New Residential Construction New Residential Sales
1 0 0 0
Construction Spending U.S. International Manufacturing and Trade
1 0 0 0
Advance Report on Durable Goods Quarterly Financial Report
1 0 0
Advance U.S. Intl Trades Monthly Wholesale Trade Quarterly Services Survey
1 0 0 0
Business Formation Statistics Total
1 0 4.940656e-324
I know that doesn't look nice, but you can see the sum of the row should be something like 1 but instead I'm ending up with this very small fraction. Am I doing something wrong here?
*** EDIT ***
> dput(head(tmp, 1))
structure(list(Organization = "VeriSign Infrastructure & Operations",
`Advance Monthly Sales` = structure(4.94065645841247e-324, class = "integer64"),
`New Residential Sales` = structure(0, class = "integer64"),
`U.S. International` = structure(0, class = "integer64"),
Other = structure(0, class = "integer64"), `New Residential Construction` = structure(0, class = "integer64"),
`Advance Report on Durable Goods` = structure(0, class = "integer64"),
`Homeownership Rate` = structure(0, class = "integer64"),
`Construction Spending` = structure(0, class = "integer64"),
`Manufacturing and Trade` = structure(0, class = "integer64"),
`Quarterly Financial Report` = structure(0, class = "integer64"),
`Advance U.S. Intl Trades` = structure(0, class = "integer64"),
`Monthly Wholesale Trade` = structure(0, class = "integer64"),
`Quarterly Services Survey` = structure(0, class = "integer64"),
`Business Formation Statistics` = structure(0, class = "integer64")), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"))
*** EDIT 2 ***
some more stuff:
> tmp$"Advance Monthly Sales"
integer64
[1] 1 0 0 1 0 0 0 0 0 2 0 0 9 0 0 0 0 0
[19] 0 0 0 0 1 0 0 0 0 1 0 0 0 8 0 0 0 1
[37] 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0
[55] 1 0 0 0 0 0 1 0 0 0 4 0 0 0 0 0 0 0
[73] 0 1 13 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0
[91] 0 0 14 0 0 0 1 0 9 0 0 0 0 0 1 0 0 0
> tmp$"Advance Monthly Sales" %>% class()
[1] "integer64"
> tmp2 <- tmp
> tmp2$"Advance Monthly Sales" <- as.numeric(tmp2$"Advance Monthly Sales")
> tmp2$"Advance Monthly Sales" %>% class()
[1] "numeric"
> dput(head(tmp2, 1))
structure(list(Organization = "VeriSign Infrastructure & Operations",
`Advance Monthly Sales` = 1, `New Residential Sales` = structure(0, class = "integer64"),
`U.S. International` = structure(0, class = "integer64"),
Other = structure(0, class = "integer64"), `New Residential Construction` = structure(0, class = "integer64"),
`Advance Report on Durable Goods` = structure(0, class = "integer64"),
`Homeownership Rate` = structure(0, class = "integer64"),
`Construction Spending` = structure(0, class = "integer64"),
`Manufacturing and Trade` = structure(0, class = "integer64"),
`Quarterly Financial Report` = structure(0, class = "integer64"),
`Advance U.S. Intl Trades` = structure(0, class = "integer64"),
`Monthly Wholesale Trade` = structure(0, class = "integer64"),
`Quarterly Services Survey` = structure(0, class = "integer64"),
`Business Formation Statistics` = structure(0, class = "integer64")), row.names = c(NA,
-1L), class = c("tbl_df", "tbl", "data.frame"))
Then I try tmp2$Total <- rowSums(tmp2[, -1]) again and I still get the following:
> head(tmp2$Total, 20)
[1] 1.000000e+00 1.976263e-322 4.940656e-324 1.000000e+00 4.940656e-324
[6] 6.958915e-320 3.952525e-323 4.940656e-324 3.458460e-323 2.000000e+00
[11] 1.037538e-322 1.235164e-322 9.000000e+00 4.940656e-324 4.940656e-324
[16] 4.940656e-324 1.828043e-322 4.940656e-324 4.940656e-324 4.001932e-322