search for: stringsasfacto

Displaying 1 result from an estimated 1 matches for "stringsasfacto".

Did you mean: stringsasfactor
2008 Nov 27
2
as.numeric in data.frame, but only where it is possible
...ow=2) mode(k) <- "numeric" # ln1 coerces numeric chars into "character" and # ln2 replaces alphabet chars with NA (with warnings) # => OK as matrix can't have mixed types k<-matrix(c("aa", "bb", 1,2, 4.3, 0), nrow=2) g<-as.data.frame(k, stringsAsFactos=FALSE) g[,2] # returns: # [1] 1 2 # Levels: 1 2 # hm... let them be levels then... sum(g[,2]) # going down in flames g[,2] <- as.numeric(g[,2]) sum(g[,2]) # is the winner of the day, # but I have a hunch that there must be something more trivial/general solution. - I'm looking for someth...