Question: I need to print input from the user in reverse order using a function. As a condition, just words (no floats/ int) should be allowed & at least **four** words need to be entered.
e.g.:
How can I help you
--> you help I can How

It should'nt be possible to input: "4 5 6 7" or "There are 2 dogs"
Here's my current code, however I didn't integrate that only strings are allowed so far:

```
def phrase():
    while True:
        user_input = input("Please insert a phrase: ")
        words = user_input.split(" ")
        n = len(words)
        if n >= 4:
            words = words[-1::-1]
            phrase_reverse = " ".join(words)
            print(phrase_reverse)
        else:
            print("Please only insert words and at least 4 ")
            continue
        break

phrase()

```

I tried with `if n<4 and words == str:`, `if n<4 and words != string` etc.. However, that didn't work. Could you please help me solving this issue? Maybe my code is wrong in general.

Answer: 
try to do this

```r
df <- structure(list(animals = c("E1", "E1", "E1", 
                           "E2", "E2", "E2"), period = structure(c(18690, 
                                                                   18697, 18704, 18690, 18697, 18704), class = "Date"), weight1 = c(704, 
                                                                                                                                    734, 653, 851, 911, 829), weight2 = c(0, 235, 325, 0, 148, 
                                                                                                                                                                          200)), row.names = c(NA, -6L), class = c("data.table", "data.frame")) 

library(dplyr)

df %>% 
  group_by(animals) %>% 
  mutate(across(starts_with("weight"), cumsum))
#> # A tibble: 6 x 4
#> # Groups:   animals [2]
#>   animals period     weight1 weight2
#>   <chr>   <date>       <dbl>   <dbl>
#> 1 E1      2021-03-04     704       0
#> 2 E1      2021-03-11    1438     235
#> 3 E1      2021-03-18    2091     560
#> 4 E2      2021-03-04     851       0
#> 5 E2      2021-03-11    1762     148
#> 6 E2      2021-03-18    2591     348

```

Created on 2021-03-24 by the [reprex package](https://reprex.tidyverse.org) (v1.0.0)

**or**

`vars <- names(df)[3:4]`

`df %>% group_by(animals) %>% mutate(across(all_of(vars), cumsum))`
Base R solution:

```
num_col_idx <- vapply(df, is.numeric, logical(1))

cbind(df[,!num_col_idx],
      data.frame(do.call(rbind, lapply(
        split(df[, num_col_idx], df$animals), cumsum)), row.names = NULL))

```