Hi all,
I have problems in a dataframe variables types.
Look:
from a loop function:
for(...){
...
dados.fin <- rbind(dados.fin, c(L=j, A=j^2,
Nsp=nsps,
N=length(amosfin$SP),
AmT="am",NAm=nam,
AMST=amst))
dados.fin <- rbind(dados.fin, c(L=j, A=j^2,
Nsp=nsp,
N=nbicho, AmT="tot",
NAm=nam,
AMST=amst))
...
}
dados.fin <- as.data.frame(dados.fin)
> summary(dados.fin)
L A Nsp N AmT NAm AMST
10:10 100:10 11 : 7 12 : 5 am :30 5:60 unif:60
12:10 144:10 7 : 7 122 : 5 tot:30
14:10 196:10 16 : 5 181 : 5
16:10 256:10 25 : 5 270 : 5
18:10 324:10 37 : 5 403 : 5
20:10 400:10 55 : 5 55 : 5
(Other):26 (Other):30
All variables appear like factors, but only AmT and AMST are really factors.
I try to use
dados.fin <- rbind(dados.fin, c(L=as.numeric(j), A=j^2,
Nsp=nsp,
N=nbicho, AmT="tot",
NAm=nam,
AMST=amst))
and some combinations like as.numeric(as.character(j)) etc.
How I make to force the types?
Thanks for all,
Ronaldo
--
Pessoas que s?o boas para arranjar desculpas raramente s?o boas em
qualquer outra coisa.
-- Benjamim Franklin
--
| // | \\ [*****************************][*******************]
|| ( ? ? ) [Ronaldo Reis J?nior ][PentiumIII-600 ]
| V [UFV/DBA-Entomologia ][HD: 30 + 10 Gb ]
|| / \ [36571-000 Vi?osa - MG ][RAM: 128 Mb ]
| /(.''`.)\ [Fone: 31-3899-2532 ][Video: SiS620-8Mb ]
||/(: :' :)\ [chrysopa at insecta.ufv.br ][Modem: Pctel-onboar]
|/ (`. `'` ) \[ICQ#: 5692561 ][Kernel: 2.4.18 ]
|| ( `- ) [*****************************][*******************]
||| _/ \_Powered by GNU/Debian W/Sarge D+ || Lxuser#: 205366
Dear Ronaldo,
Is your problem to create a data frame where character vectors remain
characters, not factors?
In documentation of as.data.frame you can read:
Character variables passed to data.frame are converted to factor
columns unless protected by I. It also applies to adding columns to
a data frame.
So you should create your data frame like
dados.fim <- data.frame(L, A, Nsp, N, I(AmT), I(NAm), I(AMST))
I don't know what is the mode of dados.fin, but probably something
happens there too.
Best wishes,
Ott
| From: "Ronaldo Reis Jr." <chrysopa at insecta.ufv.br>
| Date: Thu, 6 Mar 2003 11:46:28 -0300
|
| Hi all,
|
| I have problems in a dataframe variables types.
|
| Look:
|
| from a loop function:
| for(...){
| ...
| dados.fin <- rbind(dados.fin, c(L=j, A=j^2,
| Nsp=nsps,
| N=length(amosfin$SP),
| AmT="am",NAm=nam,
| AMST=amst))
| dados.fin <- rbind(dados.fin, c(L=j, A=j^2,
| Nsp=nsp,
| N=nbicho, AmT="tot",
| NAm=nam,
| AMST=amst))
| ...
| }
|
| dados.fin <- as.data.frame(dados.fin)
|
| > summary(dados.fin)
| L A Nsp N AmT NAm AMST
| 10:10 100:10 11 : 7 12 : 5 am :30 5:60 unif:60
| 12:10 144:10 7 : 7 122 : 5 tot:30
| 14:10 196:10 16 : 5 181 : 5
| 16:10 256:10 25 : 5 270 : 5
| 18:10 324:10 37 : 5 403 : 5
| 20:10 400:10 55 : 5 55 : 5
| (Other):26 (Other):30
|
| All variables appear like factors, but only AmT and AMST are really factors.
|
| I try to use
|
| dados.fin <- rbind(dados.fin, c(L=as.numeric(j), A=j^2,
| Nsp=nsp,
| N=nbicho, AmT="tot",
| NAm=nam,
| AMST=amst))
|
| and some combinations like as.numeric(as.character(j)) etc.
|
| How I make to force the types?