I wanted to generate a column of random numbers in R taking values between 1 and 371, but I get an error I am not able to fix.
here is the code
library(readstata13)
#load data sets
data1<- read.dta13("file1.dta", convert.factors = FALSE, select.cols=(c("var1") ))
data2<- read.dta13("file2.dta", convert.factors = FALSE, select.cols=(c("var2") ))
finaldataset <-rbindlist(list(data1, data2),idcol=TRUE)
set.seed(123456789)
finaldataset$lad<-sample(371)
this is the error message I get
Error in set(x, j = name, value = value) :
Supplied 371 items to be assigned to 36137 items of column 'lad'. If you wish to 'recycle' the RHS please use rep() to make this intent clear to readers of your code.
Any help would be much appreciated, thanks