I am creating 2 data frames and merging them. I have created duplicate codes below, Since I am new in R programming I want the same results without creating repeated codes.
category sex day flag value mean Standard deviation
1 FC F -1 a 17.2 17.01333 0.9463212
2 FC F -1 a 17.0 17.01333 0.9463212
3 FC F -1 a 18.7 17.01333 0.9463212
4 FC F -1 a 17.1 17.01333 0.9463212
5 FC F -1 a 17.2 17.01333 0.9463212
6 FC F -1 a 17.2 17.01333 0.9463212
library(dplyr)
library(plyr)
library(doBy)
library(tidyverse)
data <- read.csv("users/study.csv")
print(data)
new_table <- select(data, category, sex, day, flag,value)
target1 <- "a"
target2<-"b"
#Repeated Codes
filtered1<-filter(new_table, sex=="F", category=="FC",flag %in% target1,day==-1)
filtered1
filtered2<-filter(new_table, sex=="F", category=="FC",flag %in% target2,day==-1)
filtered2
result1<-filtered1 %>%
mutate(mean = mean(value),
`Standard deviation` = sd(value))
result2<-filtered2 %>%
mutate(mean = mean(value),
`Standard deviation` = sd(value))
#Merging the dataframes
dataframe<-do.call("rbind", list(result1,result2))
dataframe
See Question&Answers more detail:os