[R-br] Pre-tratamento de dados
Bernardo Rangel Tura
tura em centroin.com.br
Sexta Junho 22 10:25:52 BRT 2012
On 06/19/2012 12:48 PM, T Branquinho wrote:
> Boa tarde,
> Estou montando um padrão de pre-tratamento de dados, a princípio montei
> para uma matrix de 39 linhas e 31 colunas, porém gostaria de fazer de
> uma forma que funcione para qualquer tamanho de matrix. Segue o que fiz
> (Em negrito estão as informações que necessito calcular)
>
>
> M1<-matrix(min(B1[,1]),39,1);M2<-matrix(min(B1[,2]),39,1);M3<-matrix(min(B1[,3]),39,1);M4<-matrix(min(B1[,4]),39,1);M5<-matrix(min(B1[,5]),39,1);M6<-matrix(min(B1[,6]),39,1);M7<-matrix(min(B1[,7]),39,1);M8<-matrix(min(B1[,8]),39,1);M9<-matrix(min(B1[,9]),39,1);M10<-matrix(min(B1[,10]),39,1);M11<-matrix(min(B1[,11]),39,1);M12<-matrix(min(B1[,12]),39,1);M13<-matrix(min(B1[,13]),39,1);M14<-matrix(min(B1[,14]),39,1);M15<-matrix(min(B1[,15]),39,1);M16<-matrix(min(B1[,16]),39,1);M17<-matrix(min(B1[,17]),39,1);M18<-matrix(min(B1[,18]),39,1);M19<-matrix(min(B1[,19]),39,1);M20<-matrix(min(B1[,20]),39,1);M21<-matrix(min(B1[,21]),39,1);M22<-matrix(min(B1[,22]),39,1);M23<-matrix(min(B1[,23]),39,1);M24<-matrix(min(B1[,24]),39,1);M25<-matrix(min(B1[,25]),39,1);M26<-matrix(min(B1[,26]),39,1);M27<-matrix(min(B1[,27]),39,1);M28<-matrix(min(B1[,28]),39,1);M29<-matrix(min(B1[,29]),39,1);M30<-matrix(min(B1[,30]),39,1);M31<-matrix(min(B1[,31]),39,1);*Mmin*<-cbind(M1,M2,M3,M4,M5,M6,M7,M8,M9,M10!
,M11,M12,M
13,M14,M15,M16,M17,M18,M19,M20,M21,M22,M23,M24,M25,M26,M27,M28,M29,M30,M31);M1<-matrix(max(B1[,1]),39,1);M2<-matrix(max(B1[,2]),39,1);M3<-matrix(max(B1[,3]),39,1);M4<-matrix(max(B1[,4]),39,1);M5<-matrix(max(B1[,5]),39,1);M6<-matrix(max(B1[,6]),39,1);M7<-matrix(max(B1[,7]),39,1);M8<-matrix(max(B1[,8]),39,1);M9<-matrix(max(B1[,9]),39,1);M10<-matrix(max(B1[,10]),39,1);M11<-matrix(max(B1[,11]),39,1);M12<-matrix(max(B1[,12]),39,1);M13<-matrix(max(B1[,13]),39,1);M14<-matrix(max(B1[,14]),39,1);M15<-matrix(max(B1[,15]),39,1);M16<-matrix(max(B1[,16]),39,1);M17<-matrix(max(B1[,17]),39,1);M18<-matrix(max(B1[,18]),39,1);M19<-matrix(max(B1[,19]),39,1);M20<-matrix(max(B1[,20]),39,1);M21<-matrix(max(B1[,21]),39,1);M22<-matrix(max(B1[,22]),39,1);M23<-matrix(max(B1[,23]),39,1);M24<-matrix(max(B1[,24]),39,1);M25<-matrix(max(B1[,25]),39,1);M26<-matrix(max(B1[,26]),39,1);M27<-matrix(max(B1[,27]),39,1);M28<-matrix(max(B1[,28]),39,1);M29<-matrix(max(B1[,29]),39,1);M30<-matrix(max(B1[,30]),39,1);M!
31<-matrix
(max(B1[,31]),39,1);*Mmax*<-cbind(M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12,M13,M14,M15,M16,M17,M18,M19,M20,M21,M22,M23,M24,M25,M26,M27,M28,M29,M30,M31);M1<-matrix(mean(B1[,1]),39,1);M2<-matrix(mean(B1[,2]),39,1);M3<-matrix(mean(B1[,3]),39,1);M4<-matrix(mean(B1[,4]),39,1);M5<-matrix(mean(B1[,5]),39,1);M6<-matrix(mean(B1[,6]),39,1);M7<-matrix(mean(B1[,7]),39,1);M8<-matrix(mean(B1[,8]),39,1);M9<-matrix(mean(B1[,9]),39,1);M10<-matrix(mean(B1[,10]),39,1);M11<-matrix(mean(B1[,11]),39,1);M12<-matrix(mean(B1[,12]),39,1);M13<-matrix(mean(B1[,13]),39,1);M14<-matrix(mean(B1[,14]),39,1);M15<-matrix(mean(B1[,15]),39,1);M16<-matrix(mean(B1[,16]),39,1);M17<-matrix(mean(B1[,17]),39,1);M18<-matrix(mean(B1[,18]),39,1);M19<-matrix(mean(B1[,19]),39,1);M20<-matrix(mean(B1[,20]),39,1);M21<-matrix(mean(B1[,21]),39,1);M22<-matrix(mean(B1[,22]),39,1);M23<-matrix(mean(B1[,23]),39,1);M24<-matrix(mean(B1[,24]),39,1);M25<-matrix(mean(B1[,25]),39,1);M26<-matrix(mean(B1[,26]),39,1);M27<-matrix(mean(B1[,27])!
,39,1);M28
<-matrix(mean(B1[,28]),39,1);M29<-matrix(mean(B1[,29]),39,1);M30<-matrix(mean(B1[,30]),39,1);M31<-matrix(mean(B1[,31]),39,1);*Mmean*<-cbind(M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12,M13,M14,M15,M16,M17,M18,M19,M20,M21,M22,M23,M24,M25,M26,M27,M28,M29,M30,M31);
> M1<-matrix(var(B1[,1]),39,1);M2<-matrix(var(B1[,2]),39,1);M3<-matrix(var(B1[,3]),39,1);M4<-matrix(var(B1[,4]),39,1);M5<-matrix(var(B1[,5]),39,1);M6<-matrix(var(B1[,6]),39,1);M7<-matrix(var(B1[,7]),39,1);M8<-matrix(var(B1[,8]),39,1);M9<-matrix(var(B1[,9]),39,1);M10<-matrix(var(B1[,10]),39,1);M11<-matrix(var(B1[,11]),39,1);M12<-matrix(var(B1[,12]),39,1);M13<-matrix(var(B1[,13]),39,1);M14<-matrix(var(B1[,14]),39,1);M15<-matrix(var(B1[,15]),39,1);M16<-matrix(var(B1[,16]),39,1);M17<-matrix(var(B1[,17]),39,1);M18<-matrix(var(B1[,18]),39,1);M19<-matrix(var(B1[,19]),39,1);M20<-matrix(var(B1[,20]),39,1);M21<-matrix(var(B1[,21]),39,1);M22<-matrix(var(B1[,22]),39,1);M23<-matrix(var(B1[,23]),39,1);M24<-matrix(var(B1[,24]),39,1);M25<-matrix(var(B1[,25]),39,1);M26<-matrix(var(B1[,26]),39,1);M27<-matrix(var(B1[,27]),39,1);M28<-matrix(var(B1[,28]),39,1);M29<-matrix(var(B1[,29]),39,1);M30<-matrix(var(B1[,30]),39,1);M31<-matrix(var(B1[,31]),39,1);*Mvar*<-cbind(M1,M2,M3,M4,M5,M6,M7,M8,M9,M10!
,M11,M12,M
13,M14,M15,M16,M17,M18,M19,M20,M21,M22,M23,M24,M25,M26,M27,M28,M29,M30,M31)
>
>
> *N1*<-(B1-Mmin)/(Mmax-Mmin);*N2*<-(B1-Mmean)/(Mmax-Mmean);*N3*<-(B1-Mmean)/(Mmax-Mmin);*N4*<-(B1-Mmean)/Mvar;*N5*<-sqrt(B1);*N6*<-log(B1);*N7*<-log(B1,10);*N8*<-1/sqrt(B1);*N9*<-1/B1;*N*10<-log((B1-Mmin)/(Mmax-B1));
>
>
>
> Agradeço antecipadamente qualquer tipo de auxílio.
>
>
> Tales
Tales sua resposta é a seguinte:
set.seed(1)
B1 <- matrix(rpois(1209,10),nrow=39,ncol=31)
colunas <- ncol(B1)
linhas <-nrow(B1)
Mmin <- matrix(rep(apply(B1,2,min),linhas),ncol=colunas,byrow=T)
Mmax <- matrix(rep(apply(B1,2,max),linhas),ncol=colunas,byrow=T)
Mmean <- matrix(rep(apply(B1,2,mean),linhas),ncol=colunas,byrow=T)
Mvar <- matrix(rep(apply(B1,2,var),linhas),ncol=colunas,byrow=T)
N1<-(B1-Mmin)/(Mmax-Mmin)
N2<-(B1-Mmean)/(Mmax-Mmean)
N3<-(B1-Mmean)/(Mmax-Mmin)
N4<-(B1-Mmean)/Mvar
N5<-sqrt(B1)
N6<-log(B1)
N7<-log(B1,10)
N8<-1/sqrt(B1)
N9<-1/B1
N10<-log((B1-Mmin)/(Mmax-B1))
Observe que:
1- as duas primeiras linhas foram feitas para eu conseguir um exemplo
minimamente reprodutível da matriz B1, que você deveria ter fornecido.
2- se tivesse descrito as matrizes - algo como Mmin= menor valor de cada
coluna de B1 - me teria facilitado entender o código
3- A familia de comandos *pply resolve muita coisa vale a pena conhecê-los
[]s
Tura
P.S concordo com os outros que você poderia explicar melhor o problema...
Mais detalhes sobre a lista de discussão R-br