Re: [R] converting values of a dataframe to numeric (where possible)

2008-09-03 Thread Ralikwen
Ok, I think I have this it works if I use data.frame(cast(df,entityID ~ attributeID)) Ralikwen wrote: > > When I do as.matrix I loose those columns that I specified as row headers > during cast. > Maybe its because of this: > "When coercing a vector, it produces a one-column matrix, and p

Re: [R] converting values of a dataframe to numeric (where possible)

2008-09-03 Thread Ralikwen
When I do as.matrix I loose those columns that I specified as row headers during cast. Maybe its because of this: "When coercing a vector, it produces a one-column matrix, and promotes the names (if any) of the vector to the rownames of the matrix." but I cant figure out what does this mean or wha

Re: [R] converting values of a dataframe to numeric (where possible)

2008-09-03 Thread Ralikwen
This is what I was looking for. Using mode instead of as.numeric is a great idea. Many thanks. Balázs jholtman wrote: > > Try this as a solution: > >> df <- data.frame(a=letters[15:17], b=c("21","NA","23"), c=10:12, d=15:17) >> # convert to numeric >> x <- as.matrix(df) >> mode(x) <- "numeric

Re: [R] converting values of a dataframe to numeric (where possible)

2008-09-02 Thread jim holtman
Try this as a solution: > df <- data.frame(a=letters[15:17], b=c("21","NA","23"), c=10:12, d=15:17) > # convert to numeric > x <- as.matrix(df) > mode(x) <- "numeric" Warning message: In eval(expr, envir, enclos) : NAs introduced by coercion > cbind(df, RTot=rowSums(x, na.rm=TRUE)) a b c d RT

[R] converting values of a dataframe to numeric (where possible)

2008-09-02 Thread Ralikwen
Hi, I am new to R. I have a dataframe with many columns some of which contain genuine strings some numerical values as strings. The dataframe is created by cast so I have no control over the resulting data type. I want to attach columns as aggregates of other columns to the dataframe. Here is the