2

I want to create some example data and started as follows;

dat <- as.data.frame(runif(100, 0, 3000))

Now I would like to do the same thing, but create a character vector, something like:

dat <- as.data.frame(runif(100, A, Z))

What would be the easiest way to do this?

Tom
  • 2,173
  • 1
  • 17
  • 44
  • 1
    Are you looking for `dat2 <- as.data.frame(sample(LETTERS, 100, replace = TRUE))`? If you want random 'words' (strings of letters) you could try the answers here: https://stackoverflow.com/q/42734547/12957340 – jared_mamrot Mar 31 '22 at 04:56
  • 1
    I was indeed looking for sample in combination with `LETTERS`, I didn't know it was that simple! Thank you very much! – Tom Mar 31 '22 at 04:59
  • 1
    There are also some randomisation functions in the `stringi` package - `stri_rand_strings(100, 1, "[A-Z]")`. – Ritchie Sacramento Mar 31 '22 at 05:02
  • @RitchieSacramento Thank you, I was already looking for a way to limit the range of letters haha. – Tom Mar 31 '22 at 05:04
  • If you wanted "real" words there are plenty of lists available on the internet (e.g. https://ucrel.lancs.ac.uk/bncfreq/flists.html) from which you could sample after filtering by word length for example. – mkpt_uk Mar 31 '22 at 09:41

0 Answers0