search for: unfactor

Displaying 8 results from an estimated 8 matches for "unfactor".

2010 Oct 10
1
Create single vector after looping through multiple data frames with GREP
...umeric(factor) returns the level of the factor, not the value of >> the level. (See ?levels and ?factor)--that's why it's giving you those >> irrelevant integers. I always end up using something like this handy >> code snippet to deal with the situation: >> >> unfactor <- function(factors) >> # From http://psychlab2.ucr.edu/rwiki/index.php/R_Code_Snippets#unfactor >> # Transform a factor back into its factor names >> { >> return(levels(factors)[factors]) >> } >> >> Then, to get your data to where you want it, I'd...
2003 Jun 04
2
convert factor to numeric
...ns a nice numeric vector of the indexes of the levels which is usually not what I had in mind: > v <- c(25, 3.78, 16.5, 37, 109) > f <- factor(v) > f [1] 25 3.78 16.5 37 109 Levels: 3.78 16.5 25 37 109 > as.numeric(f) [1] 3 1 2 4 5 > What I really want is a function "unfactor" that returns v: > unfactor(f) [1] 25.00 3.78 16.50 37.00 109.00 Of course I could use something like > as.numeric(levels(f)[as.integer(f)]) But I just can't believe there is no R function to do this in a more readable way. Actually, the behaviour of as.numeric() doesn't...
2011 Aug 22
1
looping with paste
Dear list, I have a spacialPolygonDataFrame where variables were unnecessarily imported as factors. So I am trying to unfactor variables from spatialPolygonDataFrame at data with a loop for (i in (1:length(names( spatialPolygonDataFrame)))){ command<-paste("spatialPolygonDataFrame$names(spatialPolygonDataFrame at data[",i,"])<-as.character( spatialPolygonDataFrame$names( spatialPolygonDataFrame...
2011 Aug 24
1
Passing a large amount of parameters to a function
...ams[ii,]) } do.something fails because p1, p2,... are now factors, and i have to as.numeric() or as.char() each parameter before applying mathematical operators (such as simple multiplication). This defeats the purpose of simplifying the code. Is there any decent, simple way of doing this? Can I unfactor a row of a data.frame? or a list? (BTW, "as.numeric()" won't work since some of the parameters are strings, same goes for stringsAsFactors in data.frame) Thanks, Eran [[alternative HTML version deleted]]
2010 Oct 06
2
Converting scraped data
Dear Colleagues, I used this code to scrape data from the URL conatined within. This code should be reproducible. require("XML") library(XML) theurl <- "http://www.queensu.ca/cora/_trends/mip_2006.htm" tables <- readHTMLTable(theurl) n.rows <- unlist(lapply(tables, function(t) dim(t)[1])) class(tables) test<-data.frame(tables, stringsAsFactors=FALSE)
2012 Mar 26
0
Pareto frontier plots in three dimensions
...<- off + skirt offset <- c(offset, off) # collect } } message("offset (transposed origin) =", format(offset, digits = 2, width = 8)) message() # add the pareto frontier if ( ! opt$unpareto ) { for ( i in 1:nrow(data) ) { sen <- unFactor(data$leta)[i] # 'sen' is a string, 'unFactor' is a local unfactor function if ( opt$debug ) message(sprintf(" i = %2d scenario = %s", i, sen)) point <- unlist(data[i, vecs]) # each row with selected cols # active calls qua...
2012 Jun 01
1
Converting a pdataframe into dataframe
> a <- data.frame(name=c(rep("a",5), rep("b",5)), year=c(1989:1993, 1989:1993), var=c(1:10)) > str(a) > b <- pdata.frame(a, index=c("name","year")) > str(b) Now, I want to convert b into a data frame and have a structure similar to a. How do I do that? -- Apoorva Gupta Consultant National Institute of Public Finance and Policy
2011 Oct 17
2
Cargar un comando especifico de una libreria
Hola a tod en s, me gustaría usar solo un(os) comando(s) específico(s) de una librería pero sin cargarla entera a la manera: library(laquesea) ¿se puede hacer de alguna manera? Y saludos y gracias jm~ _______________________________ J. Miguel Marin http://www.est.uc3m.es/jmmarin Dep. of Statistics University Carlos III of Madrid Spain (E.U.)