Home > Software engineering >  Make a command for several variables
Make a command for several variables

Time:08-22

I have five different parameters that I would like to join in list_of_countries (= c() ) so when I run the the last code it approaches all variables.

In other words, a refined way of country_df$US, country_df$Canada etc...

list_of_countries
US
Canada
France
Australia
Japan
tibble(country_df$list_of_countries)

Thanks in advance.

CodePudding user response:

Are you trying to create a data.frame or a tibble?

list_of_countries<-scan(text='
US
Canada
France
Australia
Japan',what=character())

country_df <- data.frame(list_of_countries)
country_df
#>   list_of_countries
#> 1                US
#> 2            Canada
#> 3            France
#> 4         Australia
#> 5             Japan

country_df <- tibble::tibble(list_of_countries)
country_df
#> # A tibble: 5 × 1
#>   list_of_countries
#>   <chr>            
#> 1 US               
#> 2 Canada           
#> 3 France           
#> 4 Australia        
#> 5 Japan

Created on 2022-08-21 by the reprex package (v2.0.1)

  •  Tags:  
  • r
  • Related