YouTip LogoYouTip

R Func Prod

# R prod() Function - Calculate Product [![Image 3: R Language Examples](https://example.com/images/up.gif) R Language Examples](https://example.com/r/r-examples.html) The R prod() function is used to calculate the product of all elements in a vector. It is frequently used when calculating geometric mean, factorial, or combinatorial probability. The syntax of prod() function is as follows: prod(x, na.rm = FALSE) **Parameter Description:** * **x** Input vector. * **na.rm** Boolean value, default is FALSE, specifies whether to remove missing values NA. ## Example # Create vector x <-c(1, 2, 3, 4, 5) # Calculate product (equivalent to 5!) result.prod<-prod(x) print(result.prod) # Verify: compare with factorial(5) print(factorial(5)) The output of executing the above code is: 120 120 prod() can also be used with seq() to calculate the product of consecutive numbers in a specified range: ## Example # Calculate product from 3 to 8 result <-prod(3:8) print(result) # Equivalent to 3*4*5*6*7*8 print(3*4*5*6*7*8) The output of executing the above code is: 20160 20160 [![Image 4: R Language Examples](https://example.com/images/up.gif) R Language Examples](https://example.com/r/r-examples.html) [R quantile() Function - Calculate Quantile](https://example.com/r/r-func-quantile.html)[](https://example.com/r/r-func-quantile.html) [ByteArk Coding Plan supports Doubao, GLM, DeepSeek, Kimi, MiniMax and other mainstream large models, official direct supply stable and reliable. Configuration Guide Β₯9.9/month Immediate Activation](https://www.volcengine.com/activity/codingplan?utm_campaign=hw&utm_content=hw&utm_medium=devrel_tool_web&utm_source=OWO&utm_term=tutorial)[iFlytek Xingchen Coding Plan includes free model call quota, DeepSeek, GLM, Kimi, MiniMax, one-stop experience and deployment platform. Configuration Guide Β₯3.9/month Immediate Activation](https://maas.xfyun.cn/modelSquare?ch=maas_lm_l2E)
← R Func RangeR Func Plot Type β†’