I'm not sure why I'm struggling with this, but I'm trying to create a dataset where each subject ("id" in this case) has an individual IQ score. They must also read 20 letters, each letter having a unique score attached to it ("value"). In theory what I want is the 300 people in this dataset to each "read" each letter, but have a constant IQ for themselves and a constant value for each letter. For example, Subject 1 should have read letters A to T with an IQ that is randomly normally distributed. So far this is what I have:
id <- 1:300
iq <- rnorm(n=300, mean=120, sd=15)
letter <- rep(c("a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t"),15)
value <- rep(c(2,2,1,2,2,2,2,2,3,2,
3,1,3,2,1,2,2,2,1,2),15)
df <- data.frame(id,iq,letter,value)
df$id <- as.character(id)
This of course isn't helpful, if I run the head of the dataframe:
head(df)
You can see that each person has a unique IQ score, but only reads one letter, not all of them:
id iq letter value
1 1 126.35025 a 2
2 2 150.08165 b 2
3 3 105.88712 c 1
4 4 106.86652 d 2
5 5 97.86159 e 2
6 6 116.39497 f 2
What I want is something more like this:
id2 <- rep(1,4)
iq2 <- 120
letter2 <- c("a","b","c","d")
value2 <- c(2,2,1,2)
df2 <- data.frame(id2,
iq2,
letter2,
value2)
Which gives this frame for one person who "reads" 4 letters
id2 iq2 letter2 value2
1 1 120 a 2
2 1 120 b 2
3 1 120 c 1
4 1 120 d 2
How do I solve this problem?