I have two data frames with different #s of observations (one is long with 2220 obs, the other is wide with 37 obs). The data frames share the variable "SID", although in the long data frame there is 60 rows for each SID value and in the wide one there is only one. The wide data frame has an additional variable "Experimenter", each SID has a corresponding Experimenter number. I would like to make an "Experimenter" column in the long data frame, there are 60 instances for each SID though and I would like the corresponding Experimenter value to be added and repeated each time the SID value occurs (so 60 times).
Nested if-else commands for every subject seems very tedious so I'm hoping there's an alternative
I've added the dput output from each data frame, unfortunately, I'm not sure how to embed them. Right now in the long data frame "SID" is named "Subject" but they are the same variable.
Wide:
structure(list(SID = 7301:7302, Experimenter = c(2L, 1L)), .Names = c("SID",
"Experimenter"), class = "data.frame", row.names = c(NA, -2L))
Long:
structure(list(Subject = c(7301L, 7301L, 7301L), Session = c(1L,
1L, 1L), Stimtype = structure(c(1L, 1L, 1L), .Label = "Control", class =
"factor"),
Valence = structure(c(1L, 1L, 1L), .Label = "Neutral", class = "factor"),
Block = c(1L, 1L, 1L), Image = c(12L, 17L, 22L), Group = structure(c(1L,
3L, 2L), .Label = c("Neutral_1660", "Neutral_5300", "Neutral_7233"
), class = "factor"), Response = c(1L, 1L, 1L), Stimulus = c(1660L,
7233L, 5300L)), .Names = c("Subject", "Session", "Stimtype",
"Valence", "Block", "Image", "Group", "Response", "Stimulus"), class =
"data.frame", row.names = c(NA,
-3L))
If we're looking at those images, all I want to do is insert the "Experimenter" variable in the long data frame that has the value "2" whenever the "Subject" is "7301" (as is in the wide data) and so on for all the subjects.
Thank you in advance.