Let me elaborate with an example:
mystr = "foo"
intvector = c(1,2,3,4,5)
trial1 = c(mystr,intvector)
sapply(trial1,class)
trial2 = mat.or.vec(1+length(intvector),1)
trial2[1] = mystr
trial2[2:length(trial2)] = intvector
sapply(trial2,class)
Both return
foo 1 2 3 4 5
"character" "character" "character" "character" "character" "character"
As you can see, R converts/casts the numeric type to character type for me, which is not what I want. Thanks 🙂
EDIT: I will use the result to append (rbind) it directly to a data.frame, which initially will be empty, so the column classes will not yet be defined.
I believe this should work. If anyone finds a better solution, without using lists, please let me know.
Produces:
Note that we have to wrap mystr in
Iand transpose the intvector in order for this to work.