similar to: Basic Q on coercing factors in data frames to numeric

Displaying 20 results from an estimated 5000 matches similar to: "Basic Q on coercing factors in data frames to numeric"

2004 Nov 11
0
ROracle SQL length limitation
Hi All, This question was brought up some time ago but I never saw a reply so I'd like to bring it up again. When using ROracle package (version 0.5-5), I am unable to run any queries that are greater than 4000 characters in length. If I do, I get the following message: Error in oraPrepareStatement(con, statement, bind=NULL) : RS-DBI driver: (too long a statement -- it must has less than
2005 Mar 16
1
Note: "The default device has been opened to honour attempt to modify trellis settings"
R-help, I'm using a function whose end result is a trellis plot. When I call the function I get sometimes the following message: "Note: The default device has been opened to honour attempt to modify trellis settings " leading up to any plot whatsoever. I call the package 'lattice' within the function and 'detach' after plotting. I have to close the graphics
2004 Dec 22
4
Make a table
Dear useR, I have a dataset like this below, > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", + header=FALSE, # No header. + col.names = c("X","Y","Z"), + sep = ",") > prevRND.dat X Y Z 1 A A 0.950933 2 A B 0.143600 3 A C 0.956133 4 B A
2011 Jul 20
3
Coercing Logical array to Numeric array
Dear all, Coercing a logical vector to a numeric one is easy. The as.numeric function is used. However what do we use when we have a matrix or an array? Sumona
2013 Jan 23
1
problems with coercing a factor to be numeric
Dear R listers, I am trying to compute the mean of a dummy variable that is encoded as a factor. However, even though the levels of my factor are 0 - 1, when I compute the mean (after coercing the factor to be numeric), R changes 0 into 1 and 1 into yes, thus altering my expected result. Please, consider the following working example: pp <- rep(0:1, 10) pp <- factor(pp, levels=(0:1),
1999 Jun 23
1
coercing factors to matrix() --> num/char ? -- inconsistencies|?
The old factor() wars...... {{maybe don't just report that factor()s are broken by design..}} If ff is a factor, e.g., ff <- as.factor(rep(1:2,3)) f2 <- ff; levels(f2) <- c("Lo","Hi") 1) we don't allow {in R as in S-plus 3.x} arithmetic on factors, i.e. 1 + ff gives an error, and I think most of us believe this is as desired. {{if one
2011 Sep 27
2
Coercing a character zoo to a numeric
Dear R-helpers, It seems to me that a character zoo cannot be coerced to a numeric zoo. Below is a minimal example. Can someone tell me what I have done wrong? > z<-zoo(1:4,order.by=1:4) > coredata(z)<-as.character(coredata(z)) > str(z) ‘zoo’ series from 1 to 4 Data: chr [1:4] "1" "2" "3" "4" Index: int [1:4] 1 2 3 4 >
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
1999 Jun 23
2
coercing factors to matrix() --> num/char ? --
Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> wrote: > Martin Maechler <maechler at stat.math.ethz.ch> writes: [ snip... ] > > >From this logic, coercing to a matrix should coerce to character rather > > than integer/numeric codes. > > Hm. I'm not sure there really is much logic in this... Factors are > sometimes character-like, sometimes
2003 May 20
3
a quick Q about memory limit in R
Hello, there, I got this error when i tried to run " data.kr <- surf.gls(2, expcov, data, d=0.7);" "Error: cannot allocate vector of size 382890 Kb Execution halted" My data is 100x100 grid. the following is the summary of "data": > summary(data); x y z Min. : 1.00 Min. : 1.00 Min. :-1.0172 1st Qu.: 26.00
2008 Apr 23
1
S4 default for coercing
Something has changed in the S4 default for coercing. Am I now suppose to use setAs, or is there something else I should do to make this work: R version 2.7.0 (2008-04-22) .... > require("methods") > setClassUnion("OptionalPOSIXct", c("POSIXct", "NULL")) [1] "OptionalPOSIXct" > setClass("TSmetax",
2006 Nov 29
1
Matrix*vector: coercing sparse to dense matrix for arithmetic
Hi, I have a sparse Matrix (kronecker product of spline design matrices), and I need to multiply each row by a number to get another matrix. If the matrix is A and the numbers are stored in a vector k, with plain vanilla matrices I would do A*k But when using the Matrix package (class of A is "dgCMatrix"), I get the warning "coercing sparse to dense matrix for arithmetic".
2013 Feb 08
2
Coercing of types when raising a number to a series of powers
I'm trying to produce a series of powers of a number as follows: |> 0.05^0:5 [1] 1 2 3 4 5 This is not the result I expected. I guess some kind of coercion happened, since, |> class(0.05^0:5) [1] "integer" Could anyone explain me what is happening here? Thanks, -Sergio.
2008 Dec 11
1
Coercing data into a simple array
I am using acf() to get the autocorrelations of a time series. It works but I want to then get the autocorrelations into a simple list of numbers. > x <- acf(price_changes, lag.max = 12,type = "correlation",plot = FALSE) > x Autocorrelations of series ‘price_changes’, by lag 0 1 2 3 4 5 6 7 8 9 10 11 12 1.000
2012 Nov 05
1
no method for coercing this S4 class to a vector
all of a sudden, after a SparseM upgrade(?) I get this error: > str(z) Formal class 'matrix.csr' [package "SparseM"] with 4 slots ..@ ra : num [1:85372672] -0.4288 0.0397 0.0104 -0.1843 -0.1203 ... ..@ ja : int [1:85372672] 1 2 3 4 5 6 7 8 9 10 ... ..@ ia : int [1:699777] 1 123 245 367 489 611 733 855 977 1099 ... ..@ dimension: int [1:2] 699776 122
2012 Feb 07
0
gmodels error: "no method for coercing this S4 class to a vector"
Dear All, I'm having a problem using functions in the gmodels library on an object of class mer from the lmer package. Code for a reproducible example is below. # Load lme4 library and sample data library(lme4) library(faraway) library(gmodels) data(penicillin) # Fit a linear mixed effects model fit4 <- lmer(yield ~ treat + (1|blend), penicillin) # Extract confidence intervals
2009 Jan 14
2
coercing a list into matrix
Dear list, I have a list of number sequences. Each number sequence has different numbers of elements. Is there a quick way (other than to iterate through the entire list) way to coerce list to matrix with NAs filling in the short sequences? An example of what I mean is this: A <- list(c(3,2,3),c(6,5)) I'd like to get A so that it is 3 2 3 6 5 NA Best, Ken
2011 May 31
1
Coercing in R and in C (R-Extensions)
Hello, in "Writing R Extensions" I found the following stuff: "Note that these coercion functions are not the same as calling as.numeric (and so on) in R code, as they do not dispatch on the class of the object. Thus it is normally preferable to do the coercion in the calling R code." ( Writing R Extensions, 2011-04-13, page 100 ) What is meant by
2004 May 21
0
Failure to preserve package attribute when coercing S4 objects (PR#6904)
If a class is derived from a superclass using 'contains', then coercion of an object from the class to the superclass fails to preserve the 'package' attribute of class of the object. This occurs only when the derived class has no additional slots. This is a problem because the 'new' function relies on the exact identity of the class, including the package attribute.
2006 Sep 04
1
Coercing elements of a matrix from integer to double
Ive been converting elements of matrices and arrays, e.g., from Integers to double-precision, by vectorizing the matrix and then remaking it. Alternatively, I can redefine one element as double which then redefines them all. Both methods are quick, so I guess I shouldn't complain, but I would have thought there'd be something more obvious. Have I missed it? Here's my redimensioning