similar to: getting sapply to skip columns with non-numeric data?

Displaying 20 results from an estimated 9000 matches similar to: "getting sapply to skip columns with non-numeric data?"

2011 Oct 20
1
stop R from rounding
Hello, I have a column in a data frame that need to be 10 digits long. As such: Decimal.Year 1 1994.25997 2 1994.26020 However, R keeps rounding the digits. As such: Decimal.Year 1 1994.260 2 1994.260 *Is there any way to stop this from happening?* Here is how I created the data frame: x <- read.table('bats_1994_CTD.txt') colnames(x) <-
2010 Nov 09
2
Help with Iterator
Dear Experts, The following is my "Iterator". When I try to write a new function with itel, I got error. This is what I have: > supDist<-function(x,y) return(max(abs(x-y))) > > myIterator <- function(xinit,f,data=NULL,eps=1e-6,itmax=5,verbose=FALSE) { + xold<-xinit + itel<-0 + repeat { + xnew<-f(xold,data) + if (verbose) { + cat( +
2007 Jan 26
2
Using functions within functions (environment problems)
Hi everyone, I've been having difficulty writing wrapper functions for some functions where those same functions include other functions with eval() calls where the environment is specified. A very simple example using function lmer from lme4: lmerWrapper <- function(formula, data, family = gaussian, method = c("REML", "ML", "PQL", "Laplace",
2006 Jan 26
2
Prediction when using orthogonal polynomials in regression
Folks, I'm doing fine with using orthogonal polynomials in a regression context: # We will deal with noisy data from the d.g.p. y = sin(x) + e x <- seq(0, 3.141592654, length.out=20) y <- sin(x) + 0.1*rnorm(10) d <- lm(y ~ poly(x, 4)) plot(x, y, type="l"); lines(x, d$fitted.values, col="blue") # Fits great! all.equal(as.numeric(d$coefficients[1] + m
2006 May 05
1
converting code into a function - seperating a data frame with n columns into n individual vectors
I have many very large dataframes with 20 columns each. In order to conserve memory, I wish to separate the data frame into 20 vectors, each named the name of the dataframe followed by .1,.2,.3 .20. (For example purposes, one data frame is named ?testa?.) e.g. testa.1, testa.2, testa.3 I have written the code to do this (see below). I am trying to convert this into a function that I can reuse.
2001 May 23
1
Passing a string variable to Surv
Hi, I am trying to write a function to automate multiple graph generation. My data looks like: Table of numeric values with the following headers: timeM1 statusM1 xM1 timeM2 statusM2 xM2 timeM3 statusM3 xM3 1 2 3 4 5 6 Where M1,M2, M3 hve no similarity except they have a max string length of 7. Examples are mcw0045, adl0003, lei0101. Now, what I want to do is Function(M1, M2,
2003 Feb 20
2
is.numeric
Hi, I have a vector, which contains both strings and numbers, e.g. > foo <- c("str1",1234,"str2",0.9876) I want to know if a distinct element of the vector is a string or a number and took "is.numeric", but > is.numeric(foo[2]) [1] FALSE because R treats the numbers in a mixed vectors as strings: > foo [1] "str1" "1234"
2007 Jul 22
1
Package design, placement of legacy functions
I have a function XOLD() from a nearly verbatim port of legacy FORTRAN in a package. I have remplemented this function as XNEW() using much cleaner native R and built-in functions of R. I have switched the package to the XNEW(), but for historical reasons would like to retain the XOLD() somewhere in the package directory structure. An assertion through a README or other will point to
2005 Oct 04
3
Problem reading in external data and assigning data.frames within R
Hey there, I apologize if this is an irritatingly simple question ... I'm a new user. I can't understand why R flips the sign of all data values when reading in external text files (tab delimited or csv) with the read.delim or read.csv functions. The signs of data values also seem to be flipped after assigning a new data.frame from within R (xnew <-- edit(data.frame()). What am
2005 Sep 06
2
Predicting responses using ace
Hello everybody, I'm a new user of R and I'm working right now with the ACE function from the acepack library. I Have a question: Is there a way to predict new responses using ACE? What I mean is doing something similar to the following code that uses PPR (Projection Pursuit Regression): library(MASS) x <- runif(20, 0, 1) xnew <- runif(2000, 0, 1) y <- sin(x) a <- ppr(x, y,
2010 Nov 18
3
sweep by levels of a factor
Hi, I'd appreciate help with this. I have a data matrix with one column, called f in the example below, a factor. I'd like to subtract the means from each of other columns for each level of the factor. That is, in the example, to go from the first matrix below to the second. I know SWEEP will take out means, but I want to do this for each level of the factor. f x 1 2 1
2005 May 31
1
Add Columns and Order for Rbind?
I am using rbind to add one list with one row to another master list. The problem is that not all columns exist in both lists. What methods would you recommend to reorder one list based on the column names of another? If both sets have the same order and columns, I can then use rbind. I can live with columns being added to the master list set it makes the task easier using something like
2005 Feb 13
2
row equality.
I think that this is an easy one... I have a matrix where each row is an (x,y,z) triplet. Given a potential (xnew,ynew,znew) triplet I want to know if the matrix already contains a row with the new values (the space already has that point). I can do it using a for loop, but I would like to know if there is anyway in which I can do it without the for loop. I do it now like this (this
2011 Jun 14
2
Need script to create new waypoint
Dear help-list members, I am a student at Durham University (UK) conducting a PhD on spatial representation in baboons. Currently, I'm analysing the effect of sampling interval on home range calculations. I have followed the baboons for 234 days in the field, each day is represented by about 1000 waypoints (x,y coordinates) recorded at irregular time intervals. Consecutive waypoints in
2006 Aug 10
2
basic question re lm()
I am using R in a Windows environment. I have a basic question regarding lm(). I have a dataframe ?data1? with ncol=w. I know that my dependent variable is in column1. Is there a way to write the regression formula so that I can use columns 2 thru w as my independent variables? e.g. something like: ? lm(data1[,1] ~ data1[,2:w] ) ? Thanks
2006 May 16
2
Using REGEX function
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> <font face="Arial">Greetings,<br> <br> I'm running
2012 Jul 02
0
Fit circle with R
Dear Researchers, I wrote two function to fit a circle using noisy data. 1- the fitCircle() is derived from MATLAB code of * zhak Bucher* from the link http://www.mathworks.com/matlabcentral/fileexchange/5557-circle-fit/content/circfit.m 2- the CircleFitByPratt() from MATLAB code of *Nikolai Chernov *from the link
2013 Oct 15
1
randomForest: Numeric deviation between 32/64 Windows builds
Dear R Developers I'm using the great randomForest package (4.6-7) for many projects and recently stumbled upon a problem when I wrote unit tests for one of my projects: On Windows, there are small numeric deviations when using the 32- / 64-bit version of R, which doesn't seem to be a problem on Linux or Mac. R64 on Windows produces the same results as R64/R32 on Linux or Mac: >
2009 Feb 03
1
Collapsing panel data
Dear R-helpers, I've been thinking about this for some time, maybe someone can help. I have a fairly large dataset with thousands of firms, call the a, b, c, etc.. such as [,1] [,2] [1,] "A" 0.5 [2,] "" 0.2 [3,] "" 0.3 [4,] "B" 0.1 [5,] "" 0.9 [6,] "C" 0.4 Or to put it differently two vectors such as y
2012 May 05
1
what is Non-numeric argument to mathematical function in prediction ?
Hi, I tried to use naivebayes in package 'e1071'. when I use following parameter, only one predictor, there is an error. > m <- naiveBayes(iris[,1], iris[,5]) > table(predict(m, iris[,1]), iris[,5]) Error in log(sapply(attribs, function(v) { : Non-numeric argument to mathematical function However, when I use two predictors, there is not error any more. > m <-