S-plus question about length of data

  • Thread starter Thread starter ToxicBug
  • Start date Start date
  • Tags Tags
    Data Length
Click For Summary
SUMMARY

The discussion focuses on programming the Exponential Integral function in R, specifically using the function expint to compute values for a vector of data. The user encounters errors when passing a vector to expint, receiving warnings about element conditions and operand lengths. The solution involves ensuring that the input vector's length is compatible with the function's requirements, particularly that it is a multiple of 15. Additionally, addressing the warning regarding the condition's length is crucial for resolving the issue.

PREREQUISITES
  • Understanding of R programming language
  • Familiarity with the concept of vectorization in R
  • Knowledge of numerical integration techniques
  • Experience with handling warnings and errors in R
NEXT STEPS
  • Explore R's vectorization techniques to optimize function performance
  • Learn about R's integrate function for numerical integration
  • Investigate how to handle warnings in R to improve code robustness
  • Research the Exponential Integral function and its applications in R
USEFUL FOR

R programmers, data analysts, and anyone working with numerical integration in R who seeks to optimize function performance for vector inputs.

ToxicBug
Messages
84
Reaction score
0
Hello, I'm trying to figure out how to program the Exponential Integral function, and then make it compute values for a vector of data.

I have this:
Code:
expint <- function(s){ 
     integrand <- function(x) {exp(x)/x} 
     integrate(integrand, lower = -Inf, upper = s)$integral
}

if I put expint(-1) then it works, but it doesn't work if I put expint(vectorofvalues), it gives me the following error:

Warning messages:
1: Condition has 72 elements: only the first used in: e1 && e2
2: Condition has 72 elements: only the first used in: e1 || e2
Problem in bound + (sgn * (1 - nodes))/nodes: length of longer operand (72) should be a multiple of length of shorter (15)

Anyone know what I need to change for it to work with vectors?
 
Physics news on Phys.org
It looks like you need to make sure the length of your vector is a multiple of 15. You might also want to look into the "condition has 72 elements" warning, as that could be related to the error you are getting. If you can provide more information about what your vector is and how it is being used, it may help other users give you more specific advice.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 0 ·
Replies
0
Views
2K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K