Question: I'm trying to figure out the most terse way to return an array of objects from a ts function. The following function works as expected:

```
    getAuthors1(): Author[]
    {
        var authors: Author[] =
            [
                {
            FirstName: "John";
            MI: "J";        
            LastName: "Smith";                    
                }
            ];
        return authors;
    }

```

The following function errors out b/c it appears that ts won't let me return an object array directly as opposed to as a variable:

```
    getAuthors2(): Author[]
    {
        return Author[] =
            [
                {
            FirstName: "John";  
            MI: "J";        
            LastName: "Smith";                    
                }
            ];
    }

```

The following function errors out b/c a value isn't provided for MI:

```
getAuthors3(): Author[]
{
    var authors: Author[] =
        [
            {
        FirstName: "John";      
        LastName: "Smith";                    
            }
        ];
    return authors;
}

```

Questions:

1. Are values required for all object properties when creating an object initialized array?
1a. If this is the case do developers typically initialize property values in the class?
2. Is there a way to return an object array directly, similar to my getAuthors2() example above, as opposed to having to assign this to a variable and then return the variable?

Answer: 
Take one vector only, to get the mean every 24 values, you can do:

```
mean24 <- function(x) {
  dim(x) <- c(24, length(x) / 24)
  colMeans(x)
}

x <- 1:48
mean24(x)
[1] 12.5 36.5

```

So, in your case, you just have to do: 

```
apply(A, c(1, 2), mean24)

```
You could also do it with `sapply` and some indexing:

```
# create data

arr <- array(dim=c(116,152,744))
arr[] <- runif(length(arr[]))

daily <-sapply(seq(1,744,24),function(ix){
                             rowMeans(arr[,,ix:(ix+23)],dims = 2)
                             },simplify = 'array')

> str(daily)
 num [1:116, 1:152, 1:31] 0.451 0.522 0.407 0.536 0.432 ...

```

### Edit:

It's also fairly quick compared with the other solution (microbenchmark):

```
Unit: milliseconds
                        expr      min       lq     mean   median      uq      max neval
 apply(arr, c(1, 2), mean24) 464.4121 509.9772 653.9486 667.2114 699.498 1221.733   100

```

---

```
Unit: milliseconds
                                                                                                        expr
 sapply(seq(1, 744, 24), function(ix) {     rowMeans(arr[, , ix:(ix + 23)], dims = 2) }, simplify = "array")
      min       lq     mean   median       uq      max neval
 164.8211 168.3295 189.8147 171.4008 196.2403 409.9638   100

```