0

I am new to R. I read that ~ is used to connect a dependent variable with an independent variables. But I see ~ being used at the front of string as in the below 2 examples. What does that mean?

Thank you

write.csv(out.file, file = "~/Data/R/BacklogReporting/data/PastDue/global/global_stacked/past_due_global_stacked.csv", row.names = FALSE) ## directory to write stacked file to

 map_df(
    ~ data_frame(x = .x), 
    .id = "dist"
  ) 

pp12345
  • 21
  • 2
  • It's used for anonymous functions. Look up this link: http://www.rebeccabarter.com/blog/2019-08-19_purrr/#:~:text=The%20tilde%2Ddot%20shorthand%20for%20functions,-To%20make%20the&text=~%20indicates%20that%20you%20have%20started,dot%20function%20argument%20is%20always%20. – Karthik S Nov 27 '20 at 08:03
  • This is not exactly R, but used in package belonging/related to the `tidyverse` collection of packages. – s_baldur Nov 27 '20 at 08:14
  • You need to distinguish character strings from R commands. Your first example is just a [path shortcut](https://superuser.com/questions/211355/what-does-the-mean-in-a-file-path). Outside of character strings, the tilde creates a formula object. Such formula objects can be used for different purposes. You should study `help("map_df")`, which explains how that function interprets a formula. – Roland Nov 27 '20 at 08:15

0 Answers0