How to calculate mean and Sd for multiple data frames in R

user330

I have two data frames as follows,

df1
    temp    time    mot
    12  13  12
    12  13  12
    12  13  12
df2
    temp    time    mot
    7   4   2
    7   4   2
    7   4   5

Both dummy tables and please assume I have multiple columns

The logit is to calculate mean and Sd for each column to get the following table


    Var1    Mean1   SD1 Var2    Mean2   SD2
    temp1   12  0   temp2   7   0
    time1   13  0   time2   4   4
    mot1    12  0   mot2    3   1.732050808


I get stuck to do it for multiple data frames with multiple columns.

Duck

Try this:

library(dplyr)
library(tidyr)
#Code
new <- df1 %>% bind_rows(df2,.id = 'id') %>%
  pivot_longer(-id) %>%
  mutate(Var=paste0(name,id)) %>%
  group_by(Var,.drop = F) %>%
  summarise(Mean=mean(value,na.rm = T),
            SD=sd(value,na.rm = T))
#List
List <- split(new,gsub('[a-z]','',new$Var))
List <- lapply(1:length(List), function(x) {names(List[[x]])<-paste0(names(List[[x]]),x);List[[x]]})
#Bind
res <- do.call(bind_cols,List)

Output:

# A tibble: 3 x 6
  Var1  Mean1   SD1 Var2  Mean2   SD2
  <chr> <dbl> <dbl> <chr> <dbl> <dbl>
1 mot1     12     0 mot2      3  1.73
2 temp1    12     0 temp2     7  0   
3 time1    13     0 time2     4  0   

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

merge multiple data.frames [r]

From Dev

Same function over multiple data frames in R

From Dev

how to extract columns in R to make multiple data frames?

From Dev

R: How to calculate lag for multiple columns by group for data table

From Dev

How to read multiple .xlsx and generate multimple data frames in R?

From Dev

calculate average over multiple data frames?

From Dev

R -- How can I calculate group means for a list of data frames, using a different subset condition to calculate each mean?

From Dev

Taking column mean over a list of data frames in R

From Dev

calculate mean for multiple columns in data.frame

From Dev

Combine multiple data frames and calculate average

From Dev

How to calculate the mean of vectors from multiple lists?

From Dev

How to calculate 90th Percentile, SD, Mean for data in SQL

From Dev

How to join multiple data frames using dplyr?

From Dev

Using a loop to create multiple data frames in R

From Dev

Is there a way in R to ignore a "." in my data when calculating mean/sd/etc

From Dev

How to create heatmap from multiple data frames

From Dev

how to extract columns in R to make multiple data frames?

From Dev

How To Calculate Mean In R (Data Structure)

From Dev

Search multiple fields in two data Frames in R

From Dev

How to calculate the mean for a column subsetted from the data

From Dev

stacked bar chart in r for multiple data frames

From Dev

how to create data frames in r

From Dev

How to compute the mean of data frames columns that are not aligned in R

From Dev

Calculate the mean value of symmetry data in a matrix with R

From Dev

R manipulating multiple data frames using a lapply

From Dev

how to calculate mean of multiple matrices

From Dev

Naming variables in multiple data frames in R

From Dev

Group the data based on binary, and calculate mean, sd

From Dev

How to create a table in R for mean, SD, and range from particular data items?

Related Related

  1. 1

    merge multiple data.frames [r]

  2. 2

    Same function over multiple data frames in R

  3. 3

    how to extract columns in R to make multiple data frames?

  4. 4

    R: How to calculate lag for multiple columns by group for data table

  5. 5

    How to read multiple .xlsx and generate multimple data frames in R?

  6. 6

    calculate average over multiple data frames?

  7. 7

    R -- How can I calculate group means for a list of data frames, using a different subset condition to calculate each mean?

  8. 8

    Taking column mean over a list of data frames in R

  9. 9

    calculate mean for multiple columns in data.frame

  10. 10

    Combine multiple data frames and calculate average

  11. 11

    How to calculate the mean of vectors from multiple lists?

  12. 12

    How to calculate 90th Percentile, SD, Mean for data in SQL

  13. 13

    How to join multiple data frames using dplyr?

  14. 14

    Using a loop to create multiple data frames in R

  15. 15

    Is there a way in R to ignore a "." in my data when calculating mean/sd/etc

  16. 16

    How to create heatmap from multiple data frames

  17. 17

    how to extract columns in R to make multiple data frames?

  18. 18

    How To Calculate Mean In R (Data Structure)

  19. 19

    Search multiple fields in two data Frames in R

  20. 20

    How to calculate the mean for a column subsetted from the data

  21. 21

    stacked bar chart in r for multiple data frames

  22. 22

    how to create data frames in r

  23. 23

    How to compute the mean of data frames columns that are not aligned in R

  24. 24

    Calculate the mean value of symmetry data in a matrix with R

  25. 25

    R manipulating multiple data frames using a lapply

  26. 26

    how to calculate mean of multiple matrices

  27. 27

    Naming variables in multiple data frames in R

  28. 28

    Group the data based on binary, and calculate mean, sd

  29. 29

    How to create a table in R for mean, SD, and range from particular data items?

HotTag

Archive