dataframe - Data.frame in R: concatenation of two column, numbers instead of occurrences -
i have simple question, cannot find answer: have data.frame:
b=c("a","a","a","a","a","b","b","b","b","c") c=c("b","b","b","b","b","c","c","c","c","d") a<-data.frame(b,c)
why if i'd put in 1 column a$b
, a$c
vector this:
f<-c(a$b,a$c)
the result not like
> f<-c(b,c) > f [1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "c" "b" "b" "b" "b" "b" "c" "c" "c" "c" "d"
but
> f<-c(a$b,a$c) > f [1] 1 1 1 1 1 2 2 2 2 3 1 1 1 1 1 2 2 2 2 3
? in advance!
edit: tried this, looking @ possible duplicate suggest above:
> a<-data.frame(z=as.character(b),k=as.character(c)) > f<-c(a$z,a$k) > f [1] 1 1 1 1 1 2 2 2 2 3 1 1 1 1 1 2 2 2 2 3
you have set stringsasfactors
false
in data.frame()
function. otherwise strings interpreted factors, resulting in undesired output.
b <- c("a","a","a","a","a","b","b","b","b","c") c <- c("b","b","b","b","b","c","c","c","c","d") <- data.frame(b,c, stringsasfactors = f) f <- c(a$b,a$c) f [1] "a" "a" "a" "a" "a" "b" "b" "b" "b" "c" "b" "b" "b" "b" "b" "c" "c" "c" "c" "d"
Comments
Post a Comment