Reza Reza - 3 months ago 6
R Question

Choosing specific data in R

Suppose I have a function that gives two or more data out. For example, a function that gives Lower Confidence Limit and Upper Confidence limit for a statistic.

Let's say the function is like this:
CI(a,b,c,d) and then it provides two answers:

>[1] 35.25976562 0.02499848


Now, if I want to use only ONE of these two answers to write a new function, how can I get R use ONLY, say, the first answer in my new function?

Answer

head might be useful for you, this function returns the first parts of a vector in this case.

head(CI, 1) 
35.25976562 

head(CI, 2) 
35.25976562   0.02499848

Since head() is a generic function, It may also has been extended to other classes. Read more about head by typing ?head in your R console.

Comments