As I am just starting to learn the R, I want to re write the below code into the pipe operator way. however, the setting rowname and colname blocked me. I will be grateful if some one can help me, which is highly appreciated!
The original code is detailed as below,
data_3 <- c(692, 5, 0, 629, 44, 9)
table_3 <- matrix(data_3, ncol=3, byrow = TRUE)
colnames(table_3) <- c("Improved", "Hospitalized", "Death")
rownames(table_3) <- c("Treated", "Placebo")
table_3 <- as.table(table_3)
chisq.test(table_3)
fisher.test(table_3)
however, I got into trouble in the setting the colname and rowname when I tried to use the pipe operator.
c(692, 5, 0, 629, 44, 9) %>%
matrix(ncol = 3) %>%
colnames <- c("Improved", "Hospitalized", "Death")
I will be grateful if anyone could help me in this pipe operator using.
your support is highly appreciated!
Best regards,
Charles