Can someone please show me what I need to get something like this to
work
for(a in c(1:5)){
data$a<-c(a:10)
}
so that i end up with a structure
data$1<-[1,2,3,4,5,6,7,8,9,10]
data$2<-[2,3,4,5,67,8,9,10]
data$3<-[3,4,5,67,8,9,10]
data$4<-[4,5,67,8,9,10]
data$5<-[5,67,8,9,10]
thanks loads
Tom
Hmm my bad,
Thanks for your replies but I think my example was a little to simple
the actual code I'm using is:
f_haardisolve<-function(v_dataset){
#pad data to make length a power of 2
v_dataset<-f_paddata(v_dataset)
l_cooef<-list() #holder for cooefficents
i_count<-1 #identity counter
while(length(v_dataset)>0){
#seperate odd and even points
v_dataset<-f_splitpoints(v_dataset)
v_dataset<-f_haarpredict(v_dataset)
v_dataset<-f_haaruplift(v_dataset)
str_idx<-paste('c',i_count,sep='')
l_cooef
$str_idx<-v_dataset[c((length(v_dataset)/2)+1:(length(v_dataset)/2))]
#should be no wrap on the previous line
v_dataset<-v_dataset[c(1:length(v_dataset)/2)]
i_count<-i_count+1
}
l_cooef
}
In this particular case I could probably calculate the number of
iterations and use l_cooef<-names() but more is there a more generic
method for adding another column of data?
On Tue, 2005-27-09 at 10:39 -0400, tom wright wrote:> Can someone please show me what I need to get something like this to
> work
>
> for(a in c(1:5)){
> data$a<-c(a:10)
> }
>
> so that i end up with a structure
> data$1<-[1,2,3,4,5,6,7,8,9,10]
> data$2<-[2,3,4,5,67,8,9,10]
> data$3<-[3,4,5,67,8,9,10]
> data$4<-[4,5,67,8,9,10]
> data$5<-[5,67,8,9,10]
>
> thanks loads
> Tom
>
> ______________________________________________
> 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
>
Got it thanks
the trick was to create a variable with the new name
str_idx<-paste('c',i,sep='')
then use double square brackets
l_cooef[str_idx]]<-whatever()
f_haardisolve<-function(v_dataset){
#pad data to make length a power of 2
v_dataset<-f_paddata(v_dataset)
l_cooef<-list() #holder for cooefficents
i_count<-1 #identity counter
while(length(v_dataset)>0){
#seperate odd and even points
v_dataset<-f_splitpoints(v_dataset)
v_dataset<-f_haarpredict(v_dataset)
v_dataset<-f_haaruplift(v_dataset)
str_idx<-paste('c',i_count,sep='')
l_cooef[[str_idx]]<-list()
l_cooef[[str_idx]]<-v_dataset[c((length(v_dataset)/2)+1:(length(v_dataset)/2))]
v_dataset<-v_dataset[c(1:length(v_dataset)/2)]
i_count<-i_count+1
}
l_cooef
}
On Tue, 2005-27-09 at 10:39 -0400, tom wright wrote:> Can someone please show me what I need to get something like this to
> work
>
> for(a in c(1:5)){
> data$a<-c(a:10)
> }
>
> so that i end up with a structure
> data$1<-[1,2,3,4,5,6,7,8,9,10]
> data$2<-[2,3,4,5,67,8,9,10]
> data$3<-[3,4,5,67,8,9,10]
> data$4<-[4,5,67,8,9,10]
> data$5<-[5,67,8,9,10]
>
> thanks loads
> Tom
>
> ______________________________________________
> 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
>
Le 27 Septembre 2005 10:39, tom wright a ??crit??:> Can someone please show me what I need to get something like this to > work > > for(a in c(1:5)){ > data$a<-c(a:10) > } > > so that i end up with a structure > data$1<-[1,2,3,4,5,6,7,8,9,10] > data$2<-[2,3,4,5,67,8,9,10] > data$3<-[3,4,5,67,8,9,10] > data$4<-[4,5,67,8,9,10] > data$5<-[5,67,8,9,10] > > thanks loads > TomThat's an exercise I give to my students! This will create the sequences:> data <- lapply(1:5, seq, 10)You can then assign the names with> names(data) <- as.character(1:5)but 'data$1' will not work. You will need either 'data$"1"' or 'data[["1"]]'. I'd use different names... HTH. -- Vincent Goulet, Associate Professor ??cole d'actuariat Universit?? Laval, Qu??bec Vincent.Goulet at act.ulaval.ca http://vgoulet.act.ulaval.ca
When sapply is used on a character vector it will use those as the names so: data <- sapply(as.character(1:5), function(x) seq(as.numeric(x),10)) will give data with the required names. On 9/27/05, tom wright <tom at maladmin.com> wrote:> Can someone please show me what I need to get something like this to > work > > for(a in c(1:5)){ > data$a<-c(a:10) > } > > so that i end up with a structure > data$1<-[1,2,3,4,5,6,7,8,9,10] > data$2<-[2,3,4,5,67,8,9,10] > data$3<-[3,4,5,67,8,9,10] > data$4<-[4,5,67,8,9,10] > data$5<-[5,67,8,9,10] > > thanks loads > Tom > > ______________________________________________ > 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 >