An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20120720/346a65bf/attachment.pl>
Understanding cbind
4 messages · Manuel Spínola, Phil Novack-Gottshall, Mario José Marques
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20120720/65a377af/attachment.pl>
Hi Manuel,
when you use cbind(finaldf[, 3:22], cbind function waiting that you gave
second data to bind with first. How you use only one data, its result like:
DEV <- finaldf[, 3:22]
with the same structure of data frame finaldf.
When you use cbind(finaldf$oc1, finaldf$oc2,... you bind a vector of
number into columns. Its like:
v1 <- 0,0,0,1,1,1
v2 <- 1,1,1,0,0,0
...
cbind(v1, v2, ...)
that result:
[ ,1] [ ,1]
[1, ] 0 1
[2, ] 0 1
[3, ] 0 1
[4, ] 1 0
[5, ] 1 0
[6, ] 1 0
Regards,
MJ
...................................................
Mario Jos? Marques
Master student in Ecology
Institute of Biology, Dept. Plant Biology, Ecology Lab.
State University of Campinas - UNICAMP
Campinas, S?o Paulo, Brazil
On 20/07/2012 13:13, Manuel Sp?nola wrote:
Dear list members, I am using function cbind but I got 2 different results, one is a data frame and the other is a matrix and I would like to undertand why is the reason: I have a data frame called "finaldf"
names(finaldf)
[1] "especie" "estrato" "oc1" "oc2" "oc3" "oc4" "oc5" "oc6" [9] "oc7" "oc8" "oc9" "oc10" "oc11" "oc12" "oc13" "oc14" [17] "oc15" "oc16" "oc17" "oc18" "oc19" "oc20" I tried (gave me a data frame): DET <- cbind(finaldf[, 3:22])
head(DET)
oc1 oc2 oc3 oc4 oc5 oc6 oc7 oc8 oc9 oc10 oc11 oc12 oc13 oc14 oc15 oc16
oc17 oc18
1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0
27 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
0 0
53 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0
2 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 1
1 1
28 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1
1 0
54 1 1 1 1 1 1 1 1 0 0 0 1 1 0 1 0
0 0
oc19 oc20
1 0 0
27 1 0
53 0 0
2 1 1
28 1 0
54 0 1
and gave me a different results when I tried (gave me a matrix):
DET <- cbind(finaldf$oc1, finaldf$oc2, finaldf$oc3, finaldf$oc4,
finaldf$oc5, finaldf$oc6, finaldf$oc7, finaldf$oc8, finaldf$oc9,
finaldf$oc10, finaldf$oc11, finaldf$oc12, finaldf$oc13, finaldf$oc14,
finaldf$oc15, finaldf$oc16, finaldf$oc17, finaldf$oc18, finaldf$oc19,
finaldf$oc20)
head(DET)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[,14]
[1,] 0 0 0 0 0 0 0 0 1 0 0 0 0
0
[2,] 0 0 0 1 0 0 0 0 0 0 0 0 0
0
[3,] 0 0 0 0 0 0 0 0 0 0 0 0 0
0
[4,] 1 1 1 1 1 1 0 1 1 1 1 1 0
1
[5,] 1 0 1 0 1 1 1 1 1 1 1 1 0
1
[6,] 1 1 1 1 1 1 1 1 0 0 0 1 1
0
[,15] [,16] [,17] [,18] [,19] [,20]
[1,] 0 0 0 0 0 0
[2,] 0 1 0 0 1 0
[3,] 0 0 0 0 0 0
[4,] 0 1 1 1 1 1
[5,] 1 1 1 0 1 0
[6,] 1 0 0 0 0 1
Best,
Manuel
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
1 day later
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20120722/220a70fb/attachment.pl>