similar to: Applying a function to each element of an array

Displaying 20 results from an estimated 20000 matches similar to: "Applying a function to each element of an array"

2004 Sep 09
3
function "apply" and 3D arrays (PR#7221)
Full_Name: jarek tuszynski Version: 1.8.1 OS: windows 2000 Submission from: (NULL) (198.151.13.10) Example code: > a=array(1:27, c(3,3,3)) > apply(a,2, var) [,1] [,2] [,3] [1,] 1 1 1 [2,] 1 1 1 [3,] 1 1 1 [4,] 1 1 1 [5,] 1 1 1 [6,] 1 1 1 [7,] 1 1 1 [8,] 1 1 1 [9,] 1 1 1 > apply(a,2, mean) [1]
2005 Oct 04
6
Animation of Mandelbrot Set
Hi, I was playing with Mandelbrot sets and come up with the following code, I thought I would share: library(fields) # for tim.colors library(caTools) # for write.gif m = 400 # grid size C = complex( real=rep(seq(-1.8,0.6, length.out=m), each=m ), imag=rep(seq(-1.2,1.2, length.out=m), m ) ) C = matrix(C,m,m) Z = 0 X = array(0, c(m,m,20)) for (k in 1:20) { Z =
2005 May 31
2
FYI: Problems while loading package "class (VR)"
Hi, Today, I performed automatic updates of packages and somehow lost "class" package. I loaded a library that depended on it and got: Error: package 'class' could not be loaded In addition: Warning message: there is no package called 'class' in: library(pkg, character.only = TRUE, logical = TRUE, lib.loc = lib.loc) I tried to load it by instal-package: class (VR) and
2005 Mar 25
2
Casting in R
Hi, I am looking for functions that would allow me to access raw binary data of R vectors. One way would be to use: x = (1:10)*pi writeBin(x, "temp.bin") r = readBin("temp.bin", "raw", n=length(x)*8) Other to write my own C code. Is there any other simpler way? I this message is a rewording of my yesterday message "Looking for function for Double to
2005 May 26
2
Reading text files and readLine
Hi, I am trying to write a function to read in a whole text file as a single string ( so I can calculate its "sha1" hash function using package "digest"). I need a single string containing the whole file, and so far I was using paste(readLines(fileName), collapse = ""). Unfortunately this function gives me warnings : incomplete final line found by readLines on
2005 Aug 09
3
how to use the function from another package
Hi, I am trying to write a package(A) for myself and need to use a function from another package(B) which is in R already(need to install it before use). Could anyone tell me how to implement that? Also I hope that my package gives an ERROR message(something like "STOP, please install package B first") if the package B is not installed yet. It is my first time to write a package. Thanks
2005 Nov 16
5
"Warning message: package '...' was built under R version 2.3.0"
Hi, While installing precompiled packages I often get warnings like the one in the subject. I usually ignore them, but I still do not understand why windows packages are build with unreleased versions of R. Is there some way to get packages build under R-2.2.0? What are potential problems that can result from that version mismatch? My system: winXP R version: 2.2.0 Jarek Tuszynski
2005 Sep 15
2
Splitting the string at the last sub-string
Hi, I need to split a string into 2 strings, with the split point defined by the last occurrence of some substring. I come up with some convoluted code to do so: str = "Chance favors the prepared mind" sub = "e" y = unlist(strsplit(str,sub)) z = cbind(paste(y[-length(y)], sub, sep="", collapse = ""), y[length(y)]); y z z[1] z[2] Is there a simpler way
2005 May 27
1
xmlAttrs and problems with reading node attributes of XML file (b ug?)
Hi, Consider the following code: require(XML) xmlFile = paste( "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n", "<mzXML xmlns=\"a\" xmlns:xsi=\"b\" xsi:schemaLocation=\"c\">\n", "<parentFile a=\"a\" b=\"b\" />\n",
2005 Oct 01
3
dec2bin?
Hello, I just want to ask if there is any function that can convert decimal number to binary vector. Thanks a lot. Haiyong
2005 Aug 02
6
can we manage memory usage to increase speed?
Hi, Thanks for reading. I am running a process in R for microarray data analysis. RedHat Enterprise Linux 4, dual AMD CPU, 6G memory. However, the R process use only a total of <200M memory. And the CPU usage is total to ~110% for two. The program takes at least 2 weeks to run at the current speed. Is there some way we can increase the usage of CPUs and memories and speed up? Any
2005 Jun 29
2
"all connections are in use" error during lazyload stage of packa ge installation
Hi, I suddenly started getting strange errors while working on my caTools package: >RCMD install C:/programs/R/rw2011/src/library/caTools ...... preparing package caTools for lazy loading Error in file(file, "r", encoding = encoding) : all connections are in use Execution halted make: *** [lazyload] Error 1 *** Installation of caTools failed *** I searched
2005 Mar 24
1
Unexpected error "subset assignment" (bug?)
Hi, I run into following problem. It seems to me that operation in the 3rd line should be valid. > b = matrix(as.raw(0), 8,8) > q = as.raw(1:8) > b[1,] = q Error: incompatible types in subset assignment > length(b[1,]) [1] 8 > typeof(b[1,]) [1] "raw" > length(q) [1] 8 > typeof(q) [1] "raw" Is this a bug or a "feature"? Jarek
2005 Apr 27
1
Error list and debugging R code
Hi, I am trying to debug my code and looking for any tool to help me out with it. My main problem is with the error messages I can not figure out where they come from (what function produced them) and what do they mean. Is there such a think as list of error messages produced by R and standard R packages, and what do they mean? Or any tool to extract information which function produced the
2005 Jul 18
2
New functions supporting GIF file format in R
Hi, A minor announcement. I just added two functions for reading and writing GIF files to my caTools package. Input and output is in the form of standard R matrices or arrays, and standard R color-maps (palettes). The functions can read and write both regular GIF images, as well as, multi-frame animated GIFs. Most of the work is done in C level code (included), so functions do not use any
2005 Jul 07
2
about image() function in R and colors
Hi! I've got a map in R imported from a GIS (GRASS) as a vector of factors. So I've got 20 different levels in the map and I've created a vector of custom colors of exactly 20 colors in lenght. I'm trying to use image() (really plot.grassmeta() that call image()) to plot the map with those colors but it doesnt work and the colors are changed. I would like that all points
2005 Jul 15
3
Passing character strings from C code to R
Hi, I have a C code which produces array of integers and potentially a string, and I have problems passing the string out. Here is the relevant part of the code: 1 PROTECT(Ret = allocVector(INTSXP, n)); 2 ret = (int*) INTEGER(Ret); /* get pointer to R's Ret */ 3 for(i=0; i<n; i++) ret[i] = data[i]; 4 Free(data); 5 i=1; 6 if (comment) { // comment was found 7 n
2005 Jul 15
3
Passing character strings from C code to R
Hi, I have a C code which produces array of integers and potentially a string, and I have problems passing the string out. Here is the relevant part of the code: 1 PROTECT(Ret = allocVector(INTSXP, n)); 2 ret = (int*) INTEGER(Ret); /* get pointer to R's Ret */ 3 for(i=0; i<n; i++) ret[i] = data[i]; 4 Free(data); 5 i=1; 6 if (comment) { // comment was found 7 n
2005 Nov 03
3
Search within a file
Hi, I am looking for a way to search a file for position of some expression, from within R. My current code: sha1Pos = gregexpr("<sha1>", readChar(filename, file.info(filename)$size))[[1]] Works fine for small files, but text files I will be working with might get up to Gb range, so I was trying to accomplish the same without loading the whole file into R. I realize this is
2005 Oct 12
1
Questions about readBin function (Was: dec2bin?)
Hi, The latest version of R had some changes to functions "readbin() and writeBin() [which] now support raw vectors as well as filenames and connections.". As a result I am working on retiring "raw2bin" and "bin2raw" functions from "caTools" package which do exactly the same. Thanks to Prof. Ripley for bringing this change to my attention. Which brings me