similar to: control the conversion of factor to numeric

Displaying 20 results from an estimated 80000 matches similar to: "control the conversion of factor to numeric"

2012 Oct 01
1
Error messages when attempting to calculate polychoric correlation matrices
Dear R users, I am a psychology postgraduate student who is relatively new to using R. I am currently developing a psychometric scale and have run into a few problems when using R to calculate a polychoric correlation matrix for my dataset. I am trying to produce a polychoric correlation matrix for calculating ordinal reliability estimates (eg. Alpha, omega).The set consists of 439 observations
2013 Apr 01
2
Factor to numeric conversion - as.numeric(as.character(f))[f] - Language definition seems to say to not use this.
These two seem to be at odds. Is this the case? >From help(factor) - section Warning: To transform a factor f to approximately its original numeric values, as.numeric(levels(f))[f] is recommended and slightly more efficient than as.numeric(as.character(f)). >From the language definition - section 2.3.1: Factors are currently implemented using an integer array to specify the actual
2013 Apr 01
1
Factor to numeric conversion - as.numeric(levels(f))[f] - Language definition seems to say to not use this.
Note the edited subject line! I don't know why I typed it as it was before. This says that as.numeric(as.character(f)) will work regardless of the implementation, and I agree. It's the recommendation to use as.numeric(levels(f))[f] that has me wondering about section 2.3.1 of the language definition. I expect that this idiom is in widespread use, and perhaps the language definition
2011 Sep 09
3
split variable / create categories
Hi, is there a function or an easy way to convert a variable with continuous values into a categorial variable (with x levels)? here is what I mean: I want to transform x: x <- c(3.2, 1.5, 6.8, 6.9, 8.5, 9.6, 1.1, 0.6) into a 'categorial'-variable with four levels so that I get: [1] 2 2 3 3 4 4 1 1 so each element is converted into its rank- value / categorial-value (in
2009 Nov 18
2
error message; ylim + log="y"
Hi, I get a lot of error messages with this command, but I don't understand why; plot(c(),c(), xlim=c(1,10), ylim=c(0,10000), log="y") thanks for any help! [[alternative HTML version deleted]]
2011 Jul 11
2
best way to aggregate / rearrange data.frame with different data types
Hi, I have a data.frame that looks like this: Subject <- c(rep(1,4), rep(2,4), rep(3,4)) y <- rnorm(12, 3, 2) gender <- c(rep("w",4), rep("m",4), rep("w",4)) comment <- c(rep("comment A",4), rep("comment B",4), rep("comment C",4)) data <- data.frame(Subject,y,gender,comment) data Subject y gender
2006 Nov 08
1
convert factor p000345 to numeric
Dear All, I am lost about the following. I have got a large dataframe (largeset) with in the first column identification numbers as factors largeset$ID p000345 p000356 p000569 etc -- in order to use them to merge with another dataframe with numerical values (000345, 000356) I want to convert them to numerical. >as.numeric(as.character(largeset$ID)) gives NA's
2010 Aug 05
3
Plotting range of values in barplot()
Hello, I am attempting to create a bar plot that contains a range of possible response values on the x-axis of 1 to 5 and contains barplots for the number of responses even in the event that there are 0 responses. For example, I have a data set that contains values of 2, 3, 4, and 5 but I would also like my graph to show that there are no 1's. I have attached the resulting graph. The
2012 Sep 25
1
mean-aggregate – but use unique for factor variables
Hi, I have a data.frame which I want to aggregate. There are some grouping variables and some continuous variables for which I would like to have the mean. However there are also some factor-variables in the data-frame that are not grouping variables and I actually would like to aggregate these variables with the unique() function. Is that possible with the standard aggregate-function? If I
2007 Nov 20
2
Plotting Non Numeric Data
Hi, Is there a way to plot non numerical data in R? Specifically, I have an array, say with 1000 entries, where each entry is a string of 4 characters (in any order, 24 possibilities in my case). I would like on the y-axis all the strings that are in the array as labels. The x-axis I would like labeled 0 to 1000. The line is to show how the strings change as we move through the array.
2010 Aug 03
1
releveling a numeric by factor interaction
Can anyone help me with the necessary code to relevel a numeric*factor interaction term in a linear model? I would like to report the estimate, std. error and t-value for the reference factor. First, I estimated a linear model with dummy variables and was able to retrieve model estimates for the reference factor using relevel. for example: > summary(update(mod.mod, . ~ . - dummy + +
2017 Jun 23
4
duplicated factor labels.
Hmm, the danger in this is that duplicated factor levels _used_ to be allowed (i.e. multiple codes with the same level). Disallowing it is what broke read.spss() on some files, because SPSS's concept of value labels is not 1-to-1 with factors. Reallowing it with different semantics could be premature. I mean, if we hadn't had the "forbidden" step, read.spss() could have changed
2012 Dec 25
5
aggregate / collapse big data frame efficiently
Hi, I need to aggregate rows of a data.frame by computing the mean for rows with the same factor-level on one factor-variable; here is the sample code: x <- data.frame(rep(letters,2), rnorm(52), rnorm(52), rnorm(52)) aggregate(x, list(x[,1]), mean) Now my problem is, that the actual data-set is much bigger (120 rows and approximately 100.000 columns) ? and it takes very very long
2010 Aug 15
2
as.logical(factor) behaviour
Hello, According to ?as.logical: "as.logical attempts to coerce its argument to be of logical type. For factors, this uses the levels (labels)." However, > as.logical(factor(c("FALSE", "TRUE"))) [1] TRUE TRUE Shouldn't it be the same as: > as.logical(levels(factor(c("FALSE", "TRUE")))) [1] FALSE TRUE according to the
2011 Jun 05
3
How to convert a factor column into a numeric one?
I have a data frame: > head(df) Time Temp Conc Repl Log10 1 0 -20 H 1 6.406547 2 2 -20 H 1 5.738683 3 7 -20 H 1 5.796394 4 14 -20 H 1 4.413691 5 0 4 H 1 6.406547 7 7 4 H 1 5.705433 > str(df) 'data.frame': 177 obs. of 5 variables: $ Time : Factor w/ 4 levels
2007 Aug 10
3
having problems with factor()
Dear R Help, I have a set of data of heights of trees described by area that they are in. The areas are numerical (0 to 7). ht area 1 320 3 2 410 4 3 230 2 4 360 3 5 126 1 6 280 2 7 260 2 8 280 2 9 280 2 10 260 2 ....... 180 450 4 181 90 1 182 120 1 183 440 4 184 210 2 185 330 3 186 210 2 187 100 1 188 0 0 I want to convert the
2007 Aug 12
2
Convert factor to numeric vector of labels
Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: https://stat.ethz.ch/pipermail/r-help/attachments/20070812/6da70dc8/attachment.pl
2004 Aug 18
3
Revert a factor to its numeric values
I'm trying a recommendation on the help page for 'factor': > x <- c(1, 2, 1, 2) > x <- factor(x, labels = c("one", "two")) > x [1] one two one two Levels: one two > as.numeric(levels(x))[x] [1] NA NA NA NA Warning message: NAs introduced by coercion Also, > as.numeric(as.character(x)) [1] NA NA NA NA Warning message: NAs introduced by
2011 May 02
3
Help converting a data.frame to ordered factors
I have a 96x34 array of Likert scale data (96 cases, 34 items) of ordered factors (strongly disagree, disagree, neutral, agree, strongly agree) that are coded numerically (1 through 5). I cannot seem to convert this array (in any class) into ordered vectors. I have all the cases as vectors of ordered factors, but any which way I reassemble those vectors loses the ordered factors and converts
2012 Jun 13
2
adjust space between horizontal legend text in a barplot
Hi All, I produced a barplot and made a horizontal legend below the graph. Because the results are from a survey, there are three levels, namely strongly disagree/disagree, neutral and strongly agree/agree. > rownames(survey)[1] "Strongly disagree/disagree" "Neutral" "Strongly agree/agree" As in the output above, there is a large space