It is well known to everyone that R handles large data very easily. What I have trouble with is putting results of analysis performed in R in tables for publication.
I would like to explain that in an example. We have this simple dataset:
value<-cbind(c(rnorm(100,500,90),rnorm(100,800,120)))
genotype<-cbind(c(rep("A",100),rep("B",100)))
gender<-rep(c("M","F","F","F"),50)
df<-cbind(value,genotype,gender)
df<-as.data.frame(df)
colnames(df)<-c("value","genotype","gender")
df$value<-as.numeric(as.character(df$value))
I would like to analyze the data for a scientific project. To extract the information I need, I have to do this:
> quantile(subset(df,gender=="M")$value)
0% 25% 50% 75% 100%
323.6955 523.1237 655.6593 828.7438 1045.0406
> quantile(subset(df,gender=="F")$value)
0% 25% 50% 75% 100%
233.3721 520.1101 633.8767 802.2277 1149.3072
> wilcox.test((subset(df,gender=="M")$value),(subset(df,gender=="F")$value))$p.value
[1] 0.924699
> table(df$genotype)
A B
100 100
> table(df$gender)
F M
150 50
> prop.test(50,150)$p.value
[1] 6.311983e-05
> table(df$genotype,df$gender)
F M
A 75 25
B 75 25
> prop.table(table(df$genotype,df$gender),2)
F M
A 0.5 0.5
B 0.5 0.5
> prop.test(c(75,25),c(125,50))$p.value
[1] 0.2990147
Well, this gives me all the information I need, but there is a long way from this to creating a publication quality table. For this, I have to copy/paste numbers from the results into the Excel. The final product is this:
The problem is that copy/paste is incovenient, can become tedious with large amount of data, and creates the possibility of human error. Is there a way to "program" or "encode" this table directly in R, so that I cam just run the code and save the output as a .csv
file?