Re: [R] Utilizing column names to multiply over all columns

2011-08-16 Thread Hadley Wickham
>> You will get the warning that last last column is not "going right" but >> otherwise this returns what you asked for: >> >> sapply(1:length(mydf), function(i) mydf[[i]]* as.numeric(names(mydf)[i])  ) > > This suits my purposes well with a couple slight modifications: > > ## I made this into a da

Re: [R] Utilizing column names to multiply over all columns

2011-08-16 Thread Sam Albers
Thanks for the response David. On Tue, Aug 16, 2011 at 1:13 PM, David Winsemius wrote: > > On Aug 16, 2011, at 3:37 PM, Sam Albers wrote: > >> ## Hello there, >> ## I have an issue where I need to use the value of column names to >> multiply with the individual values in a column and I have many

Re: [R] Utilizing column names to multiply over all columns

2011-08-16 Thread Bert Gunter
Sorry, my second should be: scale(mydf[,1:3],center = FALSE, scale=1/as.numeric(names(mydf)[1:3])) ## ?scale -- Bert On Tue, Aug 16, 2011 at 1:30 PM, Bert Gunter wrote: > How about: > > as.matrix(mydf[,1:3]) %*%  diag(as.numeric(names(mydf)[1:3])) > > or > >  scale(mydf[,1:3],1/as.numeric(nam

Re: [R] Utilizing column names to multiply over all columns

2011-08-16 Thread Bert Gunter
How about: as.matrix(mydf[,1:3]) %*% diag(as.numeric(names(mydf)[1:3])) or scale(mydf[,1:3],1/as.numeric(names(mydf)[1:3])) ## ?scale to create your new columns? -- Bert On Tue, Aug 16, 2011 at 1:13 PM, David Winsemius wrote: > > On Aug 16, 2011, at 3:37 PM, Sam Albers wrote: > >> ## Hello

Re: [R] Utilizing column names to multiply over all columns

2011-08-16 Thread David Winsemius
On Aug 16, 2011, at 3:37 PM, Sam Albers wrote: ## Hello there, ## I have an issue where I need to use the value of column names to multiply with the individual values in a column and I have many columns to do this over. I have data like this where the column names are numbers: mydf <- data.fra

[R] Utilizing column names to multiply over all columns

2011-08-16 Thread Sam Albers
## Hello there, ## I have an issue where I need to use the value of column names to multiply with the individual values in a column and I have many columns to do this over. I have data like this where the column names are numbers: mydf <- data.frame(`2.72`=runif(20, 0, 125), `3.2