[R] Odp: Cbind query
Petr PIKAL
petr.pikal at precheza.cz
Fri Oct 22 14:23:51 CEST 2010
Hi
I am a bit puzzled what you want to do?
r-help-bounces at r-project.org napsal dne 22.10.2010 13:06:17:
>
> I am new to R and request your kind help.
>
> I have a table like the one below,
> one two
> 1 apple fruit
> 2 ball game
> 3 chair wood
> 4 wood plain
> 5 fruit banana
> 6 cloth silk
>
> Note: duplicate entries are there
>
> the task is to create relations to each each row entries, like "apple ->
> fruit" . when I tried to combine column1 with column 2 (one, two), using
> "cbind" the string is changed to numerical value...something like this
> [,1] [,2]
> [1,] 10 53
> [2,] 25 562
> [3,] 25 462
> [4,] 25 1045
> [5,] 25 488
> [6,] 26 1062
> [7,] 27 951
> [8,] 27 144
> [9,] 27 676
> [10,] 27 486
l1<-sample(letters[1:5], 10, rep=T)
l2<-sample(LETTERS[1:5], 10, rep=T)
cbind(l1, l2)
l1 l2
[1,] "a" "A"
[2,] "a" "A"
[9,] "c" "C"
[10,] "b" "B"
dat<-data.frame(l1, l2)
changes character values to factor
dat
l1 l2
1 a A
2 a A
9 c C
10 b B
str(dat)
'data.frame': 10 obs. of 2 variables:
$ l1: Factor w/ 4 levels "a","b","c","d": 1 1 4 1 4 1 4 1 3 2
$ l2: Factor w/ 5 levels "A","B","C","D",..: 1 1 4 4 4 2 4 5 3 2
and cbind turns them to numeric
cbind(dat$l1, dat$l2)
[,1] [,2]
[1,] 1 1
[2,] 1 1
[9,] 3 3
[10,] 2 2
So you shall turn your factors to character values.
But without more info from your side it is just a speculation.
Regards
Petr
>
> Please suggest me how to get the string names back like the first table
in
> the out put, using cbind.
>
> Thanks in advance
> regards
> kaarz
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Cbind-query-
> tp3006988p3006988.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list