similar to: sprintf + integer(0) problem

Displaying 20 results from an estimated 20000 matches similar to: "sprintf + integer(0) problem"

2010 Feb 15
1
argh .. if/else .. why?
Hello, would someone please help explain the following inconsistency in the if/else statement to me? The format of the if/else #3 below is ok, but if/else #1 is not? (I get an "unexpected else" type error.) In order for it to work I have to use if/else #2 Thanks .. maybe there is some reason for this, but this looks very inconsistent to me. R version 2.10.1 (2009-12-14) Ubuntu 9.04
2009 Mar 18
1
sprintf("%d", integer(0)) aborts
In R's sprintf() if any of the arguments has length 0 the function aborts. E.g., > sprintf("%d", integer(0)) Error in sprintf("%d", integer(0)) : zero-length argument > sprintf(character(), integer(0)) Error in sprintf(character(), integer(0)) : 'fmt' is not a non-empty character vector This comes up in code like x[nchar(x)==0] <-
2009 Apr 27
3
Formatting numbers
I've been trough the R documentation for about half an hour and it's not clear to me how to do this: I need to format to character a series of integers from 1 to 1000, and I like them to look like "0001" "0002", "0059", "0123" and so on. Padded with zeroes to have four digits. Cheers! Mario. r-help-request at r-project.org wrote: > Send
2009 Mar 20
1
sprintf causes a segfault (PR#13613)
Full_Name: Wacek Kusnierczyk Version: 2.8.0 and 2.10.0 r48163 OS: Ubuntu 8.04 Linux 32bit Submission from: (NULL) (129.241.198.172) the following code illustrates a problem with sprintf which consistently causes a segfault when applied to certain type of arguments. it also shows inconsistent consequences of the segfault: (e = tryCatch(stop(), error=identity)) # e is an error object
2008 May 12
5
Format integer
Hi, What's one way to convert an integer to a string with preceding 0's? such that '13' becomes '00000000013' to be put into a string I've tried formatC, but they removes all the zeros and replace it with blanks Thanks -- Regards, Anh Tran [[alternative HTML version deleted]]
2010 Jan 10
1
lme4 and function 'cholmod_start' not provided by package 'Matrix' / Ubuntu
Hello all, Using Ubuntu 9.04 and R 2.8.1. For a project I need to use the Zelig package, which in turn wants to use the lme4 package. When trying to use Zelig and it tries to its required packages I get the following error message. Error in dyn.load(file, DLLpath = DLLpath, ...) : function 'cholmod_start' not provided by package 'Matrix' Error in loadModelDeps(model) :
2010 Mar 11
2
Comparing matrices
Hello all, I have two matrices, pop and pop2, each the same number of rows and columns that I want to compare for equality. I am concerned about efficiency in this operation. I've tried a few things without success so far. Doing something simple like: if (pop==pop2) { cat('equal') } else { cat('NOT equal') } results in the warning: 1: In if (pop == pop2) { : the
2010 Apr 08
1
formatting a result table (number of digits)
Hello, Is there an easy way to format the output of a result table that R generates from a regression? I like the table, but would like to limit the number of decimal points in the entries if possible. For instance I would like only 3 digits of precision for the Value, Std.Error. (And if it would be easy to get rid of scientific notation, that would be good to know too). So ideally keep the
2003 Oct 31
1
strange sprintf() behaviour ?
This is quite strange behaviour - at least for R-novice as myself.... Consider this: > testf <- function() { x <-2; sprintf("%s %f", "x =", x); return(x) } > result <- testf() > testf <- function() { x <-2; sprintf("%s %f", "x =", x) } > result <- testf() > testf() [1] "x = 2.000000" Apparently adding return()
2015 Nov 24
2
How to create a sprintf call in IR
Hi, I created a global char array, char buffer[1024]. I want to call a function to append the string information to the buffer repeatedly. For example, I need to implement the following code, where length, a, b, c, are global variables. int length = 0; length += sprintf(buffer+length, "str%d", a); length += sprintf(buffer+length, "str%c", b); length += sprintf(buffer+length,
2012 Jul 30
2
sprintf doesn't care of escape characters
Hi. I am having trouble with something that should be simple. I am unable to get sprintf using escape sequences: > sprintf("a\nb") [1] "a\nb" > sprintf("a\"bc\"d") [1] "a\"bc\"d" But it seems to need them any way: > sprintf("a\"bc"d") Error: unexpected symbol in "sprintf("a\"bc"d"
2002 May 14
2
NaN/NA and sprintf double format
With a (late prerelease of) 1.5.0 on Windows, using sprintf on NaN yields garbage when the number of decimal is specified while it works fine for NA: > sprintf("%.2f", NA) [1] "0.00" > sprintf("%.2f", NaN) [1] "-1.#J" Not specifying the decimal precision lets both print garbage: > sprintf("%f", NaN) [1] "-1.#IND00" >
2013 Feb 15
2
sprintf in system command
hi all I am using r (2.15.2) in windows 7 32bit I want to execute an external program from r console. the program is a command line program which needs the following format to start C:/Users/.../dssp-2.0.4-win32.exe -i data_1.txt -o data_1.dssp I used the system command as: system ('C:/Users/.../dssp-2.0.4-win32.exe -i
2010 Apr 27
1
sprintf() and return() oddity
Hi,   If I use sprintf and return inside a function, sprintf doesn't print anything anymore. See the non-sense example below.   > x <- function() { a <- 888 + sprintf("xxx %s", a) } > x() [1] "xxx 888" > x <- function() { a <- 888 + sprintf("xxx %s", a) + return(a) } > x() [1] 888 Is this a bug? Cheers!! Albert-Jan
2005 Feb 15
1
Apropos sprintf behavior
If changes to sprintf behavior are being considered, would it be possible to allow some of the other K&R conversion specifiers? xX - for integer to hex conversion, and c - for ascii value to character conversion would all be useful for me. Thanks, Steve Dutky On Mon, 14 Feb 2005 11:02:20 +0000 (GMT), Prof Brian Ripley wrote: +On Mon, 14 Feb 2005, Wolfgang Huber wrote: + +> Dear
2010 May 11
2
sprintf funny behavior
> sprintf("%d",4) [1] "4" > for(i in 1:4) sprintf("%d",4) > for(i in 1:4) print(4) [1] 4 [1] 4 [1] 4 [1] 4 > Why doesn't sprintf like the for loop here
2009 Apr 19
3
flip certain bits in vector
I have a string of binary values, and I would like to flip certain bits in a set of positions. Let's say the vector p contains position [1, 3, 5, 7] vector b contains bits [1, 0, 1, 0, 1, 0, 1, 0, 1, 0] result r should be [0, 1, 0, 0, 0, 0, 0, 0, 1, 0] in pseudo code this would be something like --- r = c() for (i in 1:10) if (i in p) r = c(r, flip[i]) r ----
2009 Dec 21
2
a little bug for the function 'sprintf' (PR#14161)
Dear R-ers, I am a gratuate student from South China University of Technology. I fond the function 'sprintf' in R2.10.1 have a little bug(?): When you type in the example codes: > sprintf("%s is %f feet tall\n", "Sven", 7.1) and R returns: [1] "Sven is 7.100000 feet tall\n" this is very different from the 'sprintf' function in C/C++, for in
2009 Aug 28
6
Google's R Style Guide
Perhaps most of you have already seen this? http://google-styleguide.googlecode.com/svn/trunk/google-r-style.html Comments/Critiques? Thanks, Esmail ps: Reminds me of PEP 8 for Python http://www.python.org/dev/peps/pep-0008/ Maybe not that surprising since Python is also one of the main languages used by Google.
2008 May 09
2
which.max2()
Hello, which.max() only returns one index value, the one for the maximum value. If I want the two index values for the two largest values, is this a decent solution, or is there a nicer/better R'ish way? max2 <-function(v) { m=which.max(v) v[m] = -v[m] m2=which.max(v) result=c(m, m2) result } Seems to work ok. Thanks, Esmail