R编程算术方程逻辑

时间:2018-02-06 15:18:04

标签: r

在R编程中,解决方案或算术方程式的工作如2 + 3-4 * 6 / 3-2 ^ 3/4 + 7-6 * 2 ** 3/2 + 2-4 + 5?解决方程背后的逻辑。

1 个答案:

答案 0 :(得分:0)

为了知道R如何计算你问题中的算术表达式,你需要理解R中的运算符优先级。运算符优先级,也称为运算顺序,用于解释在R&#39 {s} Syntax帮助页面上。在任何R提示符下输入?Syntax,您就会看到:

 The following unary and binary operators are defined.  They are
 listed in precedence groups, from highest to lowest.

   ‘:: :::’           access variables in a namespace              
   ‘$ @’              component / slot extraction                  
   ‘[ [[’             indexing                                     
   ‘^’                exponentiation (right to left)               
   ‘- +’              unary minus and plus                         
   ‘:’                sequence operator                            
   ‘%any%’            special operators (including ‘%%’ and ‘%/%’) 
   ‘* /’              multiply, divide                             
   ‘+ -’              (binary) add, subtract                       
   ‘< > <= >= == !=’  ordering and comparison                      
   ‘!’                negation                                     
   ‘&  &&’            and                                          
   ‘| ||’             or                                           
   ‘~’                as in formulae                               
   ‘-> ->>’           rightwards assignment                        
   ‘<- <<-’           assignment (right to left)                   
   ‘=’                assignment (right to left)                   
   ‘?’                help (unary and binary)

这告诉您^*\之前进行评估,而+-之前会对其进行评估,依此类推。< / p>