factors

Updated with data: Error in Diff…must be factors with the same levels

笑着哭i 提交于 2019-12-13 19:18:36
问题 I hope you all can help me. I have a list with two data frames -- contests and expvar. In the data frame contests , each row is a match with the first column being the winner of the match, and the second column being the loser of the match. In the data frame expvar I have player-specific predictor variables. These are all numbers. I am trying to use the BradleyTerry2 package to analyze my data. Here is the code I am using: a <- data.frame(read.csv(file.choose())) b <- data.frame(read.csv(file

How to drop NA observation of factors conditionally when doing linear regression in R?

有些话、适合烂在心里 提交于 2019-12-12 15:23:04
问题 I'm trying to do a simple linear regression model in R. there are three factor variables in the model. the model is lm(Exercise ~ Econ + Job + Position) where "Exercise" is numeric dependent variable, the amount of time exercising. "Econ", "Job", "Position" are all factor variables. "Econ" is whether a person is employed or not. (levels = employed / not employed) "Job" is the job type a person has. There are five levels for this variable. "Position" is the position a person has in the

R: Character instead of level # on x axis when plotting?

隐身守侯 提交于 2019-12-12 04:47:44
问题 I need help plotting month names on the x axis, instead of the level the months are assigned. I am working with a "water year", so October is assigned to be level 1, and ending with September being level 12. I'm sure this is easy, I just don't often work with factors. Thanks! Research Done: Plot a character vector against a numeric vector in R R plotting, date on x axis Here is a simplified example of my data Months<-c("Jan"=4,"Feb"=5,"Mar"=6,"Apr"=7,"May"=8,"Jun"=9,"Jul"=10, "Aug"=11,"Sep"

R - factor level orders (and ggplot group axis order)

大憨熊 提交于 2019-12-12 04:05:20
问题 I am trying to control the order of discrete groups on an axis in ggplot, so I am setting the order of my factor variable. Using the levels() function actually seems to change the data in the data frame - not the way R treats the underlying ordering of the data (see below). Am I doing something wrong? which function should I use instead of levels()? thanks! head(pctCStack,4) BRK Time x 1 ICs December 2013 0.6717300 2 Managers December 2013 0.8024344 3 ICs July 2014 2.0417851 4 Managers July

In R I get “Ops.factor(left, right): level sets of factors are different” when comparing 2 data frames

徘徊边缘 提交于 2019-12-11 10:17:13
问题 I have 2 data frames (A and B, consisting of 5 columns each) created from 2 .csv files. I want to compare 2 columns (A1_maj and A2_min) from A with 2 columns from B, which consist in values of the kind A, T, C, G. This is an example: A: B: A1_maj A2_min A1_maj A2_min C T C T C T C T G A G A G A A G T C G A I have a long code but I am stuck with a command. Whenever I try to compare columns from A and B using the following logic statements I get an error message: Logic statements: A$A1_maj == B

Get factors of a number

╄→尐↘猪︶ㄣ 提交于 2019-12-08 08:32:22
问题 I need to get two factors ( x, y ) of a given number ( n ) such that: x * y <= n x * y should be as close to n as possible x and y should be as close to each other as possible. Examples: n = 16 => x = 4, y = 4 n = 17 => x = 4, y = 4 n = 18 => x = 6, y = 3 n = 20 => x = 5, y = 4 Any language will do but preferably php. EDIT -- CLARIFICATION I want to create a rectangle, x units wide * y units tall such that its area is as close to n as possible. x and y must be integers. If n is a prime number

R: Make unique the duplicated levels in all factor columns in a data frame

蹲街弑〆低调 提交于 2019-12-07 20:28:45
问题 For several days already I've been stuck with a problem in R, trying to make duplicate levels in multiple factor columns in data frame unique using a loop. This is part of a larger project. I have more than 200 SPSS data sets where the number of cases vary between 4,000 and 23,000 and the number of variables vary between 120 and 1,200 (an excerpt of one of the SPSS data sets can be found here). The files contain both numeric and factor variables and many of the factor ones have duplicated

Optimization of Algorithm [closed]

会有一股神秘感。 提交于 2019-12-06 11:23:36
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . Here is the link to the problem. The problem asks the number of solutions to the Diophantine equation of the form 1/x + 1/y = 1/z (where z = n! ). Rearranging the given equation clearly tells that the answer is

R: Why am I not getting type or class “factor” after converting columns to factor?

妖精的绣舞 提交于 2019-12-06 10:11:56
I have the following setup. df <- data.frame(aa = rnorm(1000), bb = rnorm(1000)) apply(df, 2, typeof) # aa bb #"double" "double" apply(df, 2, class) # aa bb #"numeric" "numeric" Then I try to convert one of the columns to "factor". But as you can see below, I am not getting any "factor" type or classes. Am I doing anything wrong ? df[, 1] <- as.factor(df[, 1]) apply(df, 2, typeof) # aa bb #"character" "character" apply(df, 2, class) # aa bb #"character" "character" Sorry I felt my original answer badly written. Why did I put that "matrix of factors" in the very beginning? Here is a better try.

R: Make unique the duplicated levels in all factor columns in a data frame

妖精的绣舞 提交于 2019-12-06 05:44:37
For several days already I've been stuck with a problem in R, trying to make duplicate levels in multiple factor columns in data frame unique using a loop. This is part of a larger project. I have more than 200 SPSS data sets where the number of cases vary between 4,000 and 23,000 and the number of variables vary between 120 and 1,200 (an excerpt of one of the SPSS data sets can be found here ). The files contain both numeric and factor variables and many of the factor ones have duplicated levels. I have used read.spss from the foreign package to import them in data frames, keeping the value