How to adjust dataset generation

I would like to know if there is another way to write my database below. Note that I am entering twice Segunda, twice Terca, twice Quarta, and so on in D1. What I mean is that Segunda is the same as segunda or segunda-feira. But I didn't want to have to repeat Segunda twice, for example, in D1. Is there another way to encode this?

    dayinportugues <- data.frame(
      D1 = c("Segunda", "Segunda", "Terca", "Terca","Quarta","Quarta", "Quinta", "Quinta", "Sexta","Sexta", "Sabado", "Domingo"),
     D2 = c("segunda", "segunda-feira","terca","terça-feira", "quarta","quarta-feira", "quinta","quinta-feira", "sexta","sexta-feira", "sabado", "domingo"))

> dayinportugues
        D1            D2
1  Segunda       segunda
2  Segunda segunda-feira
3    Terca         terca
4    Terca   terça-feira
5   Quarta        quarta
6   Quarta  quarta-feira
7   Quinta        quinta
8   Quinta  quinta-feira
9    Sexta         sexta
10   Sexta   sexta-feira
11  Sabado        sabado
12 Domingo       domingo

Not sure what you want to achieve. Is it this ?

dayinportugues <- tibble::tibble(
 D1 = c("Segunda",  "Terca", "Quarta", "Quinta", "Sexta","Sabado", "Domingo"),
 D2 = list(list("segunda", "segunda-feira"),list("terca","terça-feira"), list("quarta","quarta-feira"),
            list("quinta","quinta-feira"), list("sexta","sexta-feira"), list( "sabado"),list( "domingo")
          )
 )
dayinportugues <- as.data.frame(dayinportugues)
print(dayinportugues)
#>        D1                     D2
#> 1 Segunda segunda, segunda-feira
#> 2   Terca     terca, terça-feira
#> 3  Quarta   quarta, quarta-feira
#> 4  Quinta   quinta, quinta-feira
#> 5   Sexta     sexta, sexta-feira
#> 6  Sabado                 sabado
#> 7 Domingo                domingo
str(dayinportugues)
#> 'data.frame':    7 obs. of  2 variables:
#>  $ D1: chr  "Segunda" "Terca" "Quarta" "Quinta" ...
#>  $ D2:List of 7
#>   ..$ :List of 2
#>   .. ..$ : chr "segunda"
#>   .. ..$ : chr "segunda-feira"
#>   ..$ :List of 2
#>   .. ..$ : chr "terca"
#>   .. ..$ : chr "terça-feira"
#>   ..$ :List of 2
#>   .. ..$ : chr "quarta"
#>   .. ..$ : chr "quarta-feira"
#>   ..$ :List of 2
#>   .. ..$ : chr "quinta"
#>   .. ..$ : chr "quinta-feira"
#>   ..$ :List of 2
#>   .. ..$ : chr "sexta"
#>   .. ..$ : chr "sexta-feira"
#>   ..$ :List of 1
#>   .. ..$ : chr "sabado"
#>   ..$ :List of 1
#>   .. ..$ : chr "domingo"
Created on 2021-11-18 by the reprex package (v2.0.0)

when writing out by hand, you can repeat a character string (or anything) with rep() function. like

dayinportugues <- data.frame(
  D1 = c(rep("Segunda",2),rep( "Terca",2),rep("Quarta",2),rep("Quinta",2),rep( "Sexta",2), "Sabado", "Domingo"),
  D2 = c("segunda", "segunda-feira","terca","terça-feira", "quarta","quarta-feira", "quinta","quinta-feira", "sexta","sexta-feira", "sabado", "domingo"))

You can even write your own function to remove the need for ,2 param and the letters ep in rep

r2 <-function(x)rep(x,2)

dayinportugues <- data.frame(
  D1 = c(r2("Segunda"),r2( "Terca"),r2("Quarta"),r2("Quinta"),r2( "Sexta"), "Sabado", "Domingo"),
  D2 = c("segunda", "segunda-feira","terca","terça-feira", "quarta","quarta-feira", "quinta","quinta-feira", "sexta","sexta-feira", "sabado", "domingo"))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.