вот мои данные https://filebin.net/i2wpmeb19dacs3nr это очень простой расчет, но мой код грязный.
#plot
library(ggplot2)
library(Hmisc)
library(svglite)
# Basic dot plot
#to use summary stat NA rows has to be delleted (or otherwise ignored)
leaf_count_jas_comlete<-leaf_count_jas[complete.cases(leaf_count_jas), ]
#all factors to character
leaf_count_jas_comlete <- data.frame(lapply(leaf_count_jas_comlete, as.character), stringsAsFactors=FALSE)
#change class for numbers
leaf_count_jas_comlete$leaf.no.<- as.numeric(leaf_count_jas_comlete$leaf.no.)
leaf_count_jas_comlete$height..cm.<- as.numeric(leaf_count_jas_comlete$height..cm.)
svg("rplot_height..cm..svg")
ggplot(leaf_count_jas_comlete, aes(x=genotype, y=height..cm.)) +
geom_dotplot(binaxis='y', stackdir='center', binwidth = 1, dotsize = 0.3)+
stat_summary(fun.y=mean, geom="point", shape=18,
size=3, color="blue") +
stat_summary(fun.data=mean_sdl, fun.args = list(mult=1),
geom="pointrange", color="blue")
dev.off()
#calculate mean and sd per group and export to a new table
library(plyr)
##add NA count
dt <- leaf_count_jas_comlete
jas_summary<-data.frame()
jas_summary_h<-ddply(dt,~genotype,summarise,mean=mean(height..cm.),sd=sd(height..cm.))
jas_summary_l<-ddply(dt,~genotype,summarise,mean=mean(leaf.no.),sd=sd(leaf.no.))
jas_summary_h_l<-merge(jas_summary_h,jas_summary_l, by="genotype", all=TRUE)
library(plyr)
n<-count(leaf_count_jas, "genotype")
dead<-aggregate(leaf.no. ~ genotype, leaf_count_jas, function(x) {sum(is.na(x))}, na.action = NULL)
jas_summary_h_l_dead<-merge(jas_summary_h_l,dead, by="genotype", all=TRUE)
jas_summary_h_l_dead_n<-merge(jas_summary_h_l_dead,n, by="genotype", all=TRUE)
Я хотел бы начать кодирование более простым способом. Например, как сделать пустой df и заполнить его итоговыми данными, чтобы в нем был столбец с именами «genotype», mean_leaf_no, «leaf_no_sd», mean_height, height_sd, no_plants и dead_plants и постепенно заполнить его расчетами вместо слияния новых DFS? также теперь, когда у меня есть это как есть, мне нужно назвать столбцы, но я бы хотел, чтобы этот фрагмент кода можно было использовать много раз, поэтому я хотел бы, чтобы имя создавалось на основе исходных имен столбцов dfs (genotype, leaf_no , высота) так, например, если кто-то измерит «flowers_no», чтобы он мог сохранить правильное имя во всей сводной таблице. Помогите, пожалуйста, помогите.