Displaying 20 results from an estimated 40000 matches similar to: "different behavior of $ with string literal vs string variable as argument"
2012 Nov 15
4
using ifelse to remove NA's from specific columns of a data frame containing strings and numbers
Hi everyone,
I have a data frame one of whose columns is a character vector and the rest
are numeric, and in debugging a script, I noticed that an ifelse call seems
to be coercing the character column to a numeric column, and producing
unintended values as a result. Roughly, here's what I tried to do:
df: a data frame with, say, the first column as a character column and the
second and
2012 Dec 04
3
odd behavior of browser()
Hi everyone,
I normally include a call to browser() as I'm working out the kinks in my
scripts, and I am always able to step through each line by hitting
"Return", but for some reason, in the scripts I'm working on now, hitting
"Return" seems to cause execution of *all* the lines in my script. I've
restarted R several times in case it was stuck in a bad state for
2013 Feb 06
3
how to "multiply" list of matrices by list of vectors
Hi everyone,
I'd like to be able to apply lda to each 2D matrix slice of a 3D array, and
then use the scalings to obtain the corresponding lda scores.
I can use 'apply' to get a list of the lda output for each 2D slice, and
can create a list of the resulting scalings, but I'm not sure how to
multiply them in a vectorized way.
Here's how I made a list of 2D matrices
2013 May 03
2
how to parallelize 'apply' across multiple cores on a Mac
Hi everyone,
I'm trying to use apply (with a call to zoo's rollapply within) on the
columns of a 1.5Kx165K matrix, and I'd like to make use of the other cores
on my machine to speed it up. (And hopefully also leave more memory free: I
find that after I create a big object like this, I have to save my
workspace and then close and reopen R to be able to recover memory tied up
by R, but
2012 Dec 12
2
using 'apply' to apply princomp to an array of datasets
Hi everyone,
Suppose I have a 3D array of datasets, where say dimension 1 corresponds to
cases, dimension 2 to datasets, and dimension 3 to observations within a
dataset. As an example, suppose I do the following:
> x <- sample(1:20, 48, replace=TRUE)
> datasets <- array(x, dim=c(4,3,2))
Here, for each j=1,2,3, I'd like to think of datasets[,j,] as a single data
matrix with
2013 Feb 06
1
how to extract test for collinearity and constantcy used in lda
Hi everyone,
I'm trying to vectorize an application of lda to each 2D slice of a 3D
array, but am running into trouble: It seems there are quite a few 2D
slices that trigger either the "variables are collinear" warning, or worse,
trigger a "variable appears to be constant within groups" error and fails
(i.e., ceases computation rather than skips bad slice).
There are
2013 May 04
1
how to best add columns to a matrix with many columns
Hi everyone,
I have large data frame, say df1, with 165K columns, and all but the first
four columns of df1 are numeric. I transformed the numeric data and
obtained a matrix, call it data.m, with 165K - 4 columns, and then tried to
create a second data frame by replacing the numeric columns of df1 by
data.m. I did this in two ways, and both ways instantly used up all the
available memory, so
2025 Jun 02
2
Specifying a long string literal across several lines
One could also argue that paste0("a", "b", "c") is a function call
that needs to be evaluated at runtime, whereas "abc" is a string
constant understood by the parser, and often also language agnostic.
I'd assume compilers and code- and text-search tools do a better job
with the latter.
/Henrik
On Mon, Jun 2, 2025 at 2:18?PM Josiah Parry
2025 Jun 02
2
Specifying a long string literal across several lines
I suppose taste is learned as well. It does feel quite odd that the best
way to define a long string without a note or text wrapping is by being
creative with functions.
This is valid in Python, Julia, and Rust (if you add `let` and a
terminating semi-colon):
my_str = "part1\
part2\
part2"
I don't think it is abnormal to expect or desire this type of functionality
in our favorite
2025 Jun 02
1
Specifying a long string literal across several lines
Like Tomas, I find the paste0 readability to be **much** better, partly
because it allows for better indentation (as Tomas pointed out). Perhaps a
pointless email, but sometimes - for these subjective issues - it is
worthwhile to point out a difference in opinion.
Best,
Kasper
On Mon, Jun 2, 2025 at 12:27?PM Tomas Kalibera <tomas.kalibera at gmail.com>
wrote:
>
> On 6/2/25 17:37,
2025 Jun 02
2
Specifying a long string literal across several lines
> On 3 Jun 2025, at 09:34, Henrik Bengtsson <henrik.bengtsson at gmail.com> wrote:
>
> One could also argue that paste0("a", "b", "c") is a function call that needs to be evaluated at runtime, whereas "abc" is a string constant understood by the parser, and often also language agnostic. I'd assume compilers and code- and text-search tools
2011 Dec 01
2
Counting the occurences of a charater within a string
I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level.
My dataframe, x, is structured as below:
Col1
abc/def
ghi/jkl/mno
I found this code on the board but it counts all occurrences of "/" in the dataframe.
chr.pos <- which(unlist(strsplit(x,NULL))=='/')
chr.count <-
2012 Jan 20
4
extract fixed width fields from a string
Hi,
I have a data frame with one column containing string of the form "ABC...|XYZ..."
where ABC etc are fields of 6 alphanumeric characters each
and XYZ etc are fields of 8 alphanumeric characters each;
"|" is a mandatory separator;
I do not know in advance how many fields of each kind will each row contain.
I need to extract these fields from the string.
=== How do I do that?
2007 May 18
2
writing variables
Can anyone give me insight into upsrw?
I have a cyberpower PR2200 UPS (running an experimental version of the
powerpanel driver hot off the presses by Arjen (thanks Arjen!!)).
When I try to run "upsrw -s xyz=abc" to set any available variable, I
get "Set variable failed: Access denied".
What user name and password is it looking for here? My upsd.users file
has 2 users
2025 May 28
1
Specifying a long string literal across several lines
Dear All,
Perhaps this should go in r-package-devel, but I suspect that this is
going to turn into a feature request, and I want to run it by the list
before filing it in the Bugzilla.
I would like to specify a long string literal without making the line
of code too long. In R,
"abc
def"
yields the string "abc\def", and, as far as I can tell, there is no
mechanism for
2025 Jun 02
1
Specifying a long string literal across several lines
On 5/28/25 04:15, Pavel Krivitsky via R-devel wrote:
> Dear All,
>
> Perhaps this should go in r-package-devel, but I suspect that this is
> going to turn into a feature request, and I want to run it by the list
> before filing it in the Bugzilla.
>
> I would like to specify a long string literal without making the line
> of code too long. In R,
>
> "abc
>
2025 Jun 02
1
Specifying a long string literal across several lines
Tomas,
Here is a good example of where this functionality would be useful:
https://github.com/R-ArcGIS/arcgislayers/blob/2b29f4c254e7e5a1dadce8d4b0015a70dfae39d4/R/arc-open.R#L19-L56
In order to prevent R CMD check notes I have to use `paste0()` to
concatenate long URLs. If we were able to use `\` to
separate the string across multiple lines, it would make the solution much
nicer!
On Mon, Jun
2025 Jun 02
1
Specifying a long string literal across several lines
On 6/2/25 17:37, Josiah Parry wrote:
> Tomas,
>
> Here is a good example of where this functionality would be useful:
> https://github.com/R-ArcGIS/arcgislayers/blob/2b29f4c254e7e5a1dadce8d4b0015a70dfae39d4/R/arc-open.R#L19-L56
>
> In order to prevent R CMD check notes I have to use `paste0()` to
> concatenate long URLs. If we were able to use `\` to
> separate the string
2012 Aug 27
4
?nchar ?strsplit
Hi, my data frame is
x<-data.frame(ID=c("abc/def","abc/def/ghi","abc","mno/pqr/st/ab"))
I want to split my column ID using "/" as the place to split. How can I do that without telling the code how many sub-columns. I could use nchar(gsub("[^/]","",x$ID)) to get how many "/" are in each row of the column, but could
2013 Apr 29
2
Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame
Dear R forum
I have a data.frame as
cashflow_df = data.frame(instrument = c("ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC","ABC", "ABC", "PQR", "PQR",