“the condition has length > 1 and only the first element will be used” error

前端 未结 1 1976
独厮守ぢ
独厮守ぢ 2021-01-28 01:12

I have a problem with the f statement, because it\'s returning to me this error message : \"the condition has length > 1 and only the first element will be used\" I hav

相关标签:
1条回答
  • 2021-01-28 01:45

    Your comparison is a TRUE/FALSE vector with more than one element, for the if - else to work it is usually necessary a length-one logical vector that is not NA. Maybe what you need is to vectorize the conditions:

    ind <- data.summary$Src.Node.Type == "eNodeB"
    data.summary$vol.up<- NA
    data.summary$vol.down<- NA
    #for true
    data.summary$vol.up[ind]<- data.summary$Src.Dst.Sig.Vol..Bytes.[ind]
    data.summary$vol.down[ind] <- data.summary$Dst.Src.Sig.Vol..Bytes.[ind]
    data.summary
    # for false
    data.summary$vol.up[!ind]<- data.summary$Dst.Src.Sig.Vol..Bytes.[!ind]
    data.summary$vol.down[!ind] <- data.summary$Src.Dst.Sig.Vol..Bytes.[!ind]
    data.summary 
    
    0 讨论(0)
提交回复
热议问题