I'm trying to do something very simple in R that I can do in Stata but I can't quite get it right.
Here is my sample of my data
data<-data.frame(
C1=c(rep(2,5), rep(20,5), rep(70,5)),
C2=c(rep(20,5), rep(70,5), rep(80,5)),
year=rep(1990:1994, 3),
VAR1=NA,
VAR2=NA,
VAR3=NA
)
in Stata I can do this
replace VAR1=1 if CC1=2 & CC2==20 & year == 1990
replace VAR2=60 if CC1=2 & CC2==20 & year == 1990
replace VAR3=70 if CC1=2 & CC2==20 & year == 1990
annoyingly Stata syntax does not allow
replace VAR1=1 & VAR2=60 & VAR3=70 if CC1=2 & CC2==20 & year == 1990
using the first Stata code
this
data1<-data.frame(C1=c(2),C2=c(20),year=c(1990),VAR1=NA,VAR2=NA,VAR3=NA)
becomes this
data2<-data.frame(C1=c(2),C2=c(20),year=c(1990),VAR1=c(1),VAR2=c(60),VAR3=c(70))
I can't find anything similar to this problem (it's very likely that I'm not asking/looking for the right phrase)
I'd like to do either the 1st but preferably the 2nd Stata command in R.
&in two quite different senses,&is a logical operator, not punctuation in a list of things to be done. - Nick Cox