conditional statements - conditionally multiply a vector by another r -


मेरे पास निम्न सदिश है

  trans & lt; - c (-2,3,10 , -5, -2,56,0)  

और मैं प्रारंभिक संख्या सकारात्मक या नकारात्मक

के आधार पर दो वैक्टर की पसंद से प्रत्येक तत्व को गुणा करना चाहता हूं < प्री> negtrans & lt; -c (1,2,3) पोस्ट्रन & lt; -c (4,5,6,7)

परिणाम इस तरह दिखना चाहिए -2 12 50 -10 -6 336 0

यहां कुंजी को बरकरार रखने के लिए है

एक तरीका

  unsplit (मानचित्र (`*`, विभाजन (ट्रांस, ट्रांस & gt; = 0), सूची (negtrans, postrans)), ट्रांस & gt; = 0) # [1] - 2 12 50 -10 -6 336 0  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -