[R] Binding one column of characters into a dataframe factors other numeric columns

From: Ken Termiso <jerk_alert_at_hotmail.com>
Date: Fri 18 Mar 2005 - 05:30:15 EST


Hi all,

I searched through the archives, but couldn't find a fix...

Basically, I've got a bunch of numeric vectors and one character vector that I want to bind into a data frame. When I include the character vector as a column in the data frame, all the numeric columns get factored in the data frame, which makes it tough to call those columns for calculations later on. I've tried using AsIs to prevent this, but without luck...in the examples below, the object named "c" is the one that is the character column. The others are numeric.

df_without_char <- data.frame(cbind(rl, gl, cp), row.names = rownames(r)) #without char vector

df_without_char <- data.frame(cbind(rl, gl, c, cp), row.names = rownames(r))#with char vector

df <- data.frame(cbind(rl, gl, I(c), cp), row.names = rownames(r)) #try to keep char vector AsIs

df <- data.frame(cbind(rl, gl, c=I(c), cp), row.names = rownames(r)) #try to keep char vector AsIs

df <- data.frame(cbind(rl, gl, c, I(cp)), row.names = rownames(r)) #try to keep num vector AsIs

df <- data.frame(cbind(rl, gl, c, cp=I(cp)), row.names = rownames(r)) #try to keep num vector AsIs

Thanks in advance,
Ken



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Mar 18 05:38:09 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:51 EST