Question: I have 100 dataframes like this:

```
 Date         ID     Value weight
1 2018-07-16  123450  617     0.1
2 2018-07-23  123450  476     0.3
3 2018-07-30  123450  445     0.4
4 2018-08-06  123450  248     0.1 
5 2018-08-13  123450  177     0.1

```

Each data set only has the same "ID" and sum(weight) = 1

I would like to calculate the weighted standard deviation like this:

```
wm <- weighted.mean(Value, weight)

wsd <- sum(Weight * (Value - wm)^2)

```

and get the result from each ID (dataframe) like this:

```
 ID     wm      wsd
123450  0.17     0.23
245813  0.25     0.3
774658  0.58     0.44

```

Answer: 
Assuming your entire data inside a single dataframe named `mydata`

```
id_list <- unique(mydata$ID)

for(i in 1:length(id_list)) {

selected <- mydata[mydata$ID == id_list[i],]

wm <- weighted.mean(selected$Value, selected$weight)

wsd <- sum(selected$Value * (selected$Value - wm)^2)

pre_result <- data.frame(ID=id_list[i],wm=wm,wsd=wsd)

if(i==1) {

 output <- pre_result

}else{

 output <- rbind(output,pre_result)

}

}

```

If you have 100 different dataframe seperated. You may either choose to use `rbind` to bind them or make another loop to reach every single one separately.
We can write a function which calculates required values from each dataframe

```
get_return_values <- function(df) {
  wm <- with(df, weighted.mean(Value, weight))
  wsd <- with(df, sum(weight * (Value - wm)^2))
  data.frame(ID = df$ID[1], wm = wm, wsd = wsd)
}

```

Then the main task is to get all the dataframes in one list. We can do that using `mget`, but for that you need find out common pattern of names of your dataframe. Let's assume they are called `df1`, `df2`, `df3` you can get all these objects in one list by doing

```
list_df <- mget(ls(pattern = "df\\d+"))

```

If your dataframes are called something else, you can adjust the `pattern` accordingly in `ls`.

We can use `lapply` and apply `get_return_values` function to each dataframe

```
do.call(rbind, lapply(list_df, get_return_values)) 

```

You could also use `purrr::map_df` or `map_dfr` function to do the same

```
purrr::map_df(list_df, get_return_values)

```