similar to: problems with coercing a factor to be numeric

Displaying 20 results from an estimated 10000 matches similar to: "problems with coercing a factor to be numeric"

2012 Dec 10
3
equivalent of group command of the egen function in Stata
Dear R listers, I am trying to create a new variable that uniquely identifies groups of observations in a dataset. So far I couldn't figure out how to do this in R. In Stata I would simply type: egen newvar = group(dim1, dim2, dim3) Please, find below a quick example to show what I am dealing with: I have a dataset with 4 variables: var <- runif(50) ## a variable that I want to group
2012 Dec 22
1
how to control the naming of factors in regression
Dear R listers, I am regressing an ordered variable over an ordered independent variable using polr. The output lists every level of the ordered independent variable repeating its name and adding a suffix. In my case my variable is called "o.particip" and in my regression table I get the following: o.particip.L o.particip.Q o.particip.C o.particip^4 o.particip^5 o.particip^6 Is
2012 Dec 23
1
Esttab error while exporting regression results
Dear listers, I am trying to export a regression output to a latex document using the R package eststo. I have two variables: an ordered factor: group <- gl(3,5,20, labels=c("Ctl","Trt","prp")) and a continuous variable: weight <- runif(20) I want to regress weight over group, therefore I run: reg1 <- lm(weight ~ group) I wish to include the output of my
2013 Jan 10
1
help with knit_hooks
Dear R-listers, does anybody can suggest some manual where I can learn more about how the hooks in knitr work? I am trying to enclose the output of an R command in the Latex verbatim environment. I defined a hook as follows: knit_hooks$set(fsverb = function(x, options) { paste("\\begin(verbatim)\n", x, "\\end(verbatim)\n", sep = "") } then I set a chunk as
2012 Dec 21
2
how to recode an ordered factor
Dear R helpers, I'm trying to recode an ordered factor to reverse its scale, but I can't figure out how to make it. I am using the Recode function provided by the Car package. I've created an ordered variable: data$o.var1 <- ordered(data$var1, levels=c(1,2,3,4), labels =c("very satisfied", "fairly satisfied", "not very satisfied", "not at all
2013 Jan 08
2
how to label two figures in the same chunk independently with knitr
Dear R helpers, I am using knitr to run analysis with R and edit my document with Latex. I am wondering whether there is a way to include 2 or more pictures per chunk and being able to refer them in the text independently and eventually whether it is possible to give them different captions. Let me give you an example.Rnw: \documentclass{article} \title{Example} \author{FS} \begin{document}
2012 Dec 22
0
texreg error while exporting regression table
Dear listers, I am trying to export my regression table to my latex document. Let's say I have two variables: an ordered factor: group <- gl(3,5,20, labels=c("Ctl","Trt","prp")) and a continuous variable: weight <- runif(20) I want to regress group over weigth, therefore I run: reg2 <- polr(group ~ weight, Hess = TRUE, method = "logistic",
2010 Nov 09
3
Row-wise recurive function call
Dear Group, I have a following dataset: > a A B C D 1 22 3 31 40 2 26 31 36 32 3 3 7 49 16 4 24 40 27 26 5 20 45 47 0 6 34 43 11 18 7 48 48 24 2 8 3 16 39 48 9 20 49 7 21 10 17 36 47 10 > dput(a) structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L,
2011 Oct 12
3
labels in a boxplot
Dear R-listers, I have a little problem with a boxplot and I hope you can help me figuring it out. I'll try to make up some data to illustrate the issue. Sorry, if my procedures look naive, but these are my first steps in R. Any comments and/or suggestions are very welcome. let's create a vector var1: var1 <- rnorm(100) and 5 five logical vectors. In this case the vectors don't
2012 Dec 20
2
how to make a table of summary statistics
Dear R-listers, I am a newbie with R and I am struggling with something I consider very basic. I wish to produce a table (to import in a latex file) of summary statistics, but for as much as I've been looking around and trying various alternatives (plyr, reporttools, pastecs and Hmisc) I haven't found what I am looking for. Probably I am doing something wrong, but I can't figure out
2012 Feb 19
2
barplot with more than 1 variable
Dear R listers, I am trying to produce a simple (for a stata user) barplot with 4 countries on the x axis, each country observed in 2 subsequent years and 3 variables. Basically, I should have three bars for each year for each country. I am attaching the chart I made in Stata, but I am not sure you'll manage to see it! I did the following: #here I create the data-set TUSE2. The vectors mw, st
2012 Apr 20
3
Matrix multiplication by multple constants
Dear R helpers Suppose x  <- c(1:3) y  <- matrix(1:12, ncol = 3, nrow = 4) > y      [,1] [,2] [,3] [1,]    1    5    9 [2,]    2    6   10 [3,]    3    7   11 [4,]    4    8   12 I wish to multiply 1st column of y by first element of x i.e. 1, 2nd column of y by 2nd element of x i.e. 2 an so on. Thus the resultant matrix should be like > z      [,1]   [,2]    [,3] [1,]    1   
2010 Nov 07
3
regular exprs
Dear All, I would appreciate any help with the following: given the vector 'x' x <- c("Ass1", "Ass.s1", "Ass2", "Ass.s2") I would like to pick up the positions where the character string contains "Ass" but does not contain "Ass.s", so for 'x' that would be positions 1 and 3. I guess this could be programmed around
2012 Nov 01
3
convert list without same component length to matrix
Hi, I have this lame question. I want to convert a list (each with varies in length) to matrix with same row length by eliminating vectors outside the needed range. For example: l<-list(NULL) l[[1]]=1,2,3.7 l[[2]]=3,4,5,6,3 l[[3]]=4,2,5,7 l[[4]]=2,4,6,3,2 l[[5]]=3,5,7,2 #so say I want to only have 4 rows and 5 column in my matrix (or data.frame) and eliminating the 5th index value in l[[2]]
2011 Aug 23
4
Correlation discrepancy
Dear R list, I have one very elementary question regrading correlation between two variables. x = c(44,46,46,47,45,43,45,44) y = c(44,43,41,41,46,48,44,43) > cov(x, y) [1] -2.428571 However, if I try to calculate the covariance using the formula as covariance = sum((x-mean(x))*(y-mean(y)))/8       # no of of paired obs. = 8 or     covariance = sum(x*y)/8-(mean(x)*mean(y)) gives
2010 Oct 15
4
split data with missing data condition
Dear all I have data like this: x y [1,] 59.74889 3.1317081 [2,] 38.77629 1.7102589 [3,] NA 2.2312962 [4,] 32.35268 1.3889621 [5,] 74.01394 1.5361227 [6,] 34.82584 1.1665412 [7,] 42.72262 2.7870875 [8,] 70.54999 3.3917257 [9,] 59.37573 2.6763249 [10,] 68.87422 1.9697770 [11,] 19.00898 2.0584415 [12,] 60.27915 2.5365194 [13,] 50.76850
2012 Mar 06
2
Numerical Inversion of Cumulative Distribution Function
Dear R users, Given a user-defined cumulative distribution function F, I want to compute F^{-1}(x). How is that possible with R? Best Regards, -- Gildas Mazo PhD student MISTIS team at INRIA Grenoble, France [[alternative HTML version deleted]]
2002 May 02
2
coercing "numeric" components of data frame to "factor" or "ordered"?
I am getting ready to load a bunch of data into R. The data is all numeric, but some of the numbers are integer codes representing non-numeric semantics. What is the best way to "fix" the data frames so that these compenents are recognized as "factors" or "ordered", as appropriate? Can I "assign" to some attribute of the data frame component, like the
2012 Mar 05
1
problems reading a large dta dataset in R
Dear R listers, I have a silly problem. I am trying to load a dta (Stata) file in R. The dta is about 650 MB and contains the integrated World Values Survey/ European Value Study data-set. My problem is that I don't manage to load the file. After almost 3 hours after I issued the following command: data <-
2011 Apr 19
2
Several factors same levels
This is probably very simple but I'm new to R so apologies for being stupid. I have some data with No coded as 0 and yes coded as 1. e.g. id sex alcohol smoker 1 M 0 1 2 F 1 0 3 M 0 0 I realise I can covert the numerical variable back to a factor by falcohol<-factor(alcohol,levels=0:1) levels<-c("No","Yes")