I made a data.table by:
p1 <- list(N=999)
d = data.table(ID = 1:p1$N)
d[,Initial_Grouping := (1:.N - 1) %/% 333]
So I get for "ID 1:333", "Initial_Grouping" = 0; "ID 334:667", "Initial_Grouping" = 1; ID 667:999", "Initial_Grouping" = 2
Now, I would like to use the rnorm function and form a 3rd column "Size" which contains random variables for each of the "Initial_Grouping". I want each of the groups to have a different and specific mean and standard deviation.
One of the things I tried is this:
d[,Firm_Size := as.integer(exp((rnorm(333,mean=3,sd=1,by = (d$Initial_Grouping ==0))))),
as.integer(exp((rnorm(333,mean=3,sd=1,by = (d$Initial_Grouping ==1))))),
as.integer(exp((rnorm(333,mean=3,sd=1,by = (d$Initial_Grouping ==2)))))]
# Error in `[.data.table`(d, , `:=`(Size, as.integer(exp((rnorm(333, :
# Provide either by= or keyby= but not both