次のデータフレームがあります。
id1 id2 qtty cat output
15994 15994 30 1 1
25787 26275 7 2 1
122301 122301 0 0 0
36199 35333 14 2 1
36199 36199 15 1 1
46223 45746 14 2 1
46223 46223 15 1 1
80570 80570 0 0 0
55728 55728 1 1 1
94218 94218 0 0 0
69456 66837 5 2 1
cat
次の基準に従って生成する列はどこですか。
id1=id2 and qtty=0 then cat=0
id1=id2 and qtty>0 then cat=1
id1!=id2 and qtty=0 then cat=2
id1!=id2 and qtty>0 then cat=2
output
私が得ているものであり、私がしたことは次のとおりです。
status<-function(dataframe){
store<-rep(0,length(dataframe[,1]))
for(i in 1: length(dataframe[,1])) {
if(dataframe[i,1]==dataframe[i,2]) {
if(dataframe[i,3]==0) {store[i]<-0}
else
if(dataframe[i,1]==dataframe[i,2]) {
if(dataframe[i,3]>0) {store[i]<-1}
else
if(dataframe[i,1]!=dataframe[i,2]) {
if(dataframe[i,3]>0) {store[i]<-2}
else store[i]<-2
}
}
}
}
return(store)
}
どんな助けでも大歓迎です。