[R] I think a simple question

Jeffrey Robert Spies jspies at nd.edu
Sun Nov 12 23:43:30 CET 2006


Sorry to hit the list three times in a row, but forgot to create the  
array in the function; note, always test after doing rm(list=ls()).

everyOther <- function(tempin, x){
	tempout <- array(data=NA, dim=length(tempin)*2)
	tempout[seq(1,length(tempin)*2, by=2)]<-tempin
	tempout[seq(2,length(tempin)*2, by=2)]<-tempin+x
	tempout
}

Usage: everyOther(seq(1,1411, by=30), 5)

Sorry,

Jeff.

On Nov 12, 2006, at 5:35 PM, Jeffrey Robert Spies wrote:

> Funciton form:
>
> everyOther <- function(tempin, x){
> 	tempout[seq(1,length(tempin)*2, by=2)]<-tempin
> 	tempout[seq(2,length(tempin)*2, by=2)]<-tempin+x
> 	tempout
> }
>
> Jeff.
>
> On Nov 12, 2006, at 5:31 PM, Jeffrey Robert Spies wrote:
>
>> tempin <- seq(1, 1411, by=30)
>> tempout <- array(data=NA, dim=length(tempin)*2)
>> tempout[seq(1,length(tempin)*2, by=2)]<-tempin
>> tempout[seq(2,length(tempin)*2, by=2)]<-tempin+5
>>
>> Is this what you're looking for?
>>
>> Jeff.
>>
>> On Nov 12, 2006, at 5:20 PM, Leeds, Mark (IED) wrote:
>>
>>> I have index ( of a vector ) values of say
>>>
>>> tempin<-c(1 31 61   91 121     all the way upto 1411)
>>>
>>> What I want is a function that takes in a number say, x = 5, and  
>>> gives
>>> me an new vector
>>> of
>>>
>>> tempout<-1  6 31  36 91  96  121  126  .......... 1411   1416
>>>
>>> This can't be so hard but I can't get it and I've honestly tried.
>>> Obviously, tempin + 5 gives me the missing values but I don't  
>>> know how
>>> to interwine them in the order above. Thanks for any help
>>> you can provide.
>>>
>>>                                                                mark
>>> --------------------------------------------------------
>>>
>>> This is not an offer (or solicitation of an offer) to buy/se... 
>>> {{dropped}}
>>>
>>> ______________________________________________
>>> R-help at stat.math.ethz.ch mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting- 
>>> guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>



More information about the R-help mailing list