search for: mysum

Displaying 20 results from an estimated 22 matches for "mysum".

2006 Mar 09
1
Linking Rblas
...SHLIB is there a way to link against a library such as Rblas (I am on a Windows platform) on a case to case basis? I played a bit around with some self-written C-code which should call the function 'dasum' defined in Blas.h. I encountered the following problem: u:\codeplay>Rcmd SHLIB mysumming.c Rcmd SHLIB mysumming.c gcc --shared -s -o mysumming.dll mysumming.def mysumming.a -LU:/R/R-2.2.0/src/gnuwin32 -lg2c -lR mysumming.a(mysumming.o)(.text+0x1b):mysumming.c: undefined reference to `dasum_' collect2: ld returned 1 exit status make: *** [mysumming.dll] Error 1 My (very li...
2011 Nov 20
2
Adding two or more columns of a data frame for each row when NAs are present.
I am fairly new to R and would like help with the problem below. I am trying to sum and count several rows in the data frame yy below. All works well as in example 1. When I try to add the columns, with an NA in Q21, I get as NA as mySum. I would like NA to be treated as O, or igored. I wrote a function to try to count an NA element as 0, Example 3 function. It works with a few warnings, Example 4, but still gives NA instead of the addition when there is an NA in an element. In Example 6 & 7, I tried using sum() but it just...
2006 Mar 09
0
Linking Rblas [under Windows]
...Windows platform) on a case to case > > basis? > > > > I played a bit around with some self-written C-code which > should call > > the function 'dasum' defined in Blas.h. > > I encountered the following problem: > > > > u:\codeplay>Rcmd SHLIB mysumming.c > > Rcmd SHLIB mysumming.c > > gcc --shared -s -o mysumming.dll mysumming.def mysumming.a > > -LU:/R/R-2.2.0/src/gnuwin32 -lg2c -lR > > mysumming.a(mysumming.o)(.text+0x1b):mysumming.c: undefined > reference to > > `dasum_' > > collect2: ld retu...
2003 Dec 10
0
dyn.load for c code
...g how to load C code into R-1.8.0 on Windows 98. To this end I wrote a small c program, downloaded the tools, perl, and mingw on the "building R for windows" page, and proceeded to create libR.a & libRblas.a as explained in the readme.packages. I started with a simple c program called mysum.c that can be found on: http://www.okada.jp.org/RWiki/?R%A4%AB%A4%E9%C2%BE%B8%C0%B8%EC%CD%F8%CD%D1 If the c program is called mysum.c, I type, after cd'ing into R_home\bin on the MS-DOS shell: > rcmd shlib [-o mysum.dll] mysum.c and the output reads: >MkRules:93: warning: overriding...
2013 Jan 16
1
How to call Java main method using rJava package?
...rying to integrate my Java program with R using rJava package. I want to execute the whole Java program from R. The main() method in my Java code calls all the other defined methods. So, I guess I have to call the main() method in .jcall. An example Java code: *class A { public static int mySum(int x, int y) { return x+y; } public static void main (String[] arg) { System.out.println("The sum is " + mySum(2, 4)); } }* I can do the following to call the mySum() method: *.jcall(obj, "I", "mySum", as.intege...
2007 Jun 28
3
Function call within a function.
...n(file, alpha , beta ) { cda <- subset(file, file[,1] == alpha) cdb <- subset (file, file[,1]== beta) list1 <- list(cda,cdb) } # funtion to operate on list ukn <- function(file, alpha, beta, nam1){ aa <- alpha bb <- beta myfile <- file nts <- lstfun(myfile, aa, bb) mysum <- nam1[,3]*5 return(mysum) } results <- ukn(dd1, "a", "b", nts$cda)
2011 Nov 10
3
optim seems to be finding a local minimum
...tion "transformIV" transforms a data frame column "IV" using parameters .alpha & .beta: ## It returns a data frame column IV_transf: transformIV = function(.alpha,.beta) { IV_transf <- as.data.frame(1 - (1/exp((IV/.beta)^.alpha))) return(IV_transf) } ### Function "mysum" calculates the sum of absolute residuals after a regression with a single predictor: mysum<- function(myIV,myDV){ regr<-lm(myDV[[1]] ~ 0 + myIV[[1]]) mysum<-sum(abs(regr$resid)) return(mysum) } ### Function to be optimized; ### param is a vector of 2 values (.alpha and .beta)...
2007 Dec 07
4
Using R function in Excel
Does anyone know a way that an function written in R can be called within a cell of an Excel spreadsheet. I would like to use the R function much as I use the native Excel functions, e.g. instead of using the excel function sum, =sum(A2,A6), I would like to use the function mysum written in R, e.g. =mysum(A2,A6). Thanks, John John Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 41...
2011 Mar 30
3
optim and optimize are not finding the right parameter
...d <- rep(0,(length(pred))) for(i in 1:length(DV_pred)){ DV_pred[i] <- a * (1- exp( (0-b)*pred[i] )) } return(DV_pred) } ## I define Function 2 that computes the sum of squared deviations for predicted DV from actual DV: my.function <- function(param){ b<-param a<-max(DV) mysum <- sum((DV - calc_DV_pred(a,b))^2) return(mysum) } If I test my function for parameter b =0.0000001, then I get a very good fit: pred<-c(0,3000000,7800000,15600000,23400000,131200000) DV<-c(0,500,1000,1400,1700,1900) test<-my.function(0.0000001) (test) # I get 11,336.81 However, whe...
2005 Apr 15
4
function corresponding to map of perl
Is there a function in R that corresponds to the function ``map'' of perl? It could be called like: vector.a <- map( vector.b, FUN, args.for.FUN ) It should execute for each element ele.b of vector.b: FUN( vector.b, args.for.FUN) It should return a vector (or data.frame) of the results of the calls of FUN. It nearly works using: apply( data.frame( vector.b ), 1, FUN,
2006 Jun 01
4
A coding question
Dear List: I have the follow code: y <- replicate(10,replicate(8,sum(rnorm(rpois(1,5))))) Now I need to apply the following condition to _every_ randomly generated Normal number in the code above: x - max(0,x-15) + max(0,x-90), where x represents the individual Normal numbers. In other words, the said condition needs to be applied before replicate(...(replicate(...(sum(...))) takes place.
2009 Mar 08
3
Thread creation in Wine
...nyone does know what is the benefit from switching from one to other option? Attaching some stupid code used by MT testing: Code: #include <iostream> #include <cmath> #include <pthread.h> extern "C" void *my_th(void *param) { const unsigned int CNT=1024; double mysum=0.0; for(unsigned int j = 0; j< CNT; j++) for(unsigned int k=0; k < CNT; k++) for(unsigned int i=0; i<CNT; i++) mysum += i; std::cout << "mysum: " << mysum << std::endl; return 0; } int main(int argc, char *argv[]) { pthread_t pthread_id, pthread_i...
2008 Dec 07
5
How to force aggregate to exclude NA ?
...10 4 D NA 7 5 E NA NA > aggregate(m[,-c(1:2)], by=list(m[,1]), length) Group.1 C D 1 A 3 3 2 B 5 5 3 C 4 4 4 D 3 3 5 E 5 5 My own defined version of length and sum to exclude NA > mylength <- function(x) { sum(as.logical(x), na.rm=T) } > mysum <- function(x) {sum(x, na.rm=T)} > aggregate(m[,-c(1:2)], by=list(m[,1]), mysum) <----------------- this computes correctly. Group.1 C D 1 A 3 2 2 B 15 13 3 C 10 10 4 D 6 7 5 E 9 8 > aggregate(m[,-c(1:2)], by=list(m[,1]), mylength) <------...
2009 Jul 14
1
Incorrect comment about ISNA(x) in Arith.h (PR#13826)
...Venables & Ripley S Programming p 137 indicates that "ISNA does not detect NaN s" Here's a little .c file and R transcript that shows that V&R are correct, ISNA(x) is not True for NaN So the last comment should read /* True for NA, not NaN #include "R.h" void mysum(double *x) { double sum = 0.0; sum = x[0] + x[1] + x[2]; if (ISNA(sum)) PROBLEM "sum is NA" WARNING(NULL_ENTRY); if (ISNAN(sum)) PROBLEM "sum is NAN" WARNING(NULL_ENTRY); if (!(R_FINITE(sum))) PROBLEM "sum is not finite" WARNING(NULL_ENTRY); ret...
2006 Oct 30
2
[LLVMdev] "fork" and "sync" for LLVM thread support - any comments?
...hope) all that's required. A PATRONIZING EXAMPLE: Summing the numbers in an array, using two threads: %sumB = global int 0 int %sumfun(%base, %offset, %count) [simple loop adding numbers from base[offset] to base[offset+count]] void %sumwrap(int *base, int %offset, int %count) %mysum = call int %sumfun(%base, %offset, %count) store int %mysum, int %sumB sync ubyte(42) ret void int %main(void) %array = malloc [1000 x uint] %sumA = call int %sumfun(%array, 0, 500) fork void %sumwrap(%array, 500, 500) sync ubyte (42) %sum = add int %sumA, %sumB ret int...
2011 Dec 26
4
Summary tables of large datasets including character and numerical variables
Hello ! I am attempting to switch from being a long time SAS user to R, and would really appreciate a bit of help ! The first thing I do in getting a large dataset (thousands of obervations and hundreds of variables) is to run a SAS command PROC CONTENTS VARNUM command - this provides me a table with the name of each variable, its type and length; then I run a PROC MEANS - for numerical
2007 Oct 01
3
mean of subset of rows
Dear list, this must be an easy one: I have a data.frame of two columns, "ID" with four different levels (A to D) and numerical "size", and each of the 4 different IDs is repeated a different number of times. I would like to get the mean size for each ID as another data.frame. I have tried the following: >ID= as.character(unique(data[,1])) # I use unique() because
2010 Jun 03
1
[LLVMdev] call a extern C function
How can i interface llvm bitcode with a existent so library... like when you use C prebuilt cos() or sin() ... suppose that i create a sum() in c/c++ compile a .so lib with it and call it from "the bitcode" program... how can i do this? Thanks Fabio Kaminski -------------- next part -------------- An HTML attachment was scrubbed... URL:
2004 May 10
2
Lists and outer() like functionality?
Hi, I'm have a list of integer vectors and I want to perform an outer() like operation on the list. As an example, take the following list: mylist <- list(1:5,3:9,8:12) A simple example of the kind of thing I want to do is to find the sum of the shared numbers between each vector to give a result like: result <- array(c(15,12,0,12,42,17,0,17,50), dim=c(3,3)) Two for() loops is the
2004 Sep 26
2
Sweave: superfluous newline (`\\') in tex file
...----------------------schnipp------------------------->8--- \documentclass{article} \begin{document} \SweaveOpts{echo=FALSE} @ <<>>= rm(list=c(ls())) library(Hmisc) library(ISwR) data(energy) energy$log <- log(energy$expend) attach(energy) @ %def @ <<results=tex>>= mysum <- summary(stature ~ expend + log, method="reverse", test=T) latex(mysum, file='', caption="foo bar", label="tab:foobar" ) @ %def \end{document} --8<------------------------schnapp------------------------->8--- Here's the resul...