Displaying 20 results from an estimated 10000 matches similar to: "substr gives empty output"
2018 Jan 22
2
substr gives empty output
In
y <- substr(x, i, 1)
your third integer needs to be the location not the number of digits, so change it to
y <- substr(x, i, i)
and you should get what you want.
Cheers,
Tim
> Date: Sun, 21 Jan 2018 10:50:31 -0500
> From: Ek Esawi <esawiek at gmail.com>
> To: Luigi Marongiu <marongiu.luigi at gmail.com>, r-help at r-project.org
> Subject: Re: [R] substr
1999 Aug 03
3
RW 0.64.2 substring() string truncation?
Hi,
(First, apology for my earlier incorrectly addressed "subscribe"
post.)
Can somebody tell me what exactly is going on below. Basically, I am
running into some kind of "string truncation" problem when I try
to get a substring starting past the 8192nd character (see sample
session below). There doesn't appear to be any problem creating the
string, and nchar()
2008 Oct 29
6
substring/strsplit question
Dear R People:
Here is a toy example:
> x <- c("2E","5W","12H")
> substr(x,2,2)
[1] "E" "W" "2"
>
Sometimes x has 3 elements, sometimes 2. I want to extract the last
element, and then extract the other 1 or 2 elements.
How can I do this, please?
TIA,
Sincerely,
Erin
--
Erin Hodgess
Associate Professor
Department of
2013 Jan 30
2
substring from behind
Hello together,
i have a question for "substring".
I know i can filter a number like this one:
bill$No<-substring(bill$Customer,2,4)
in this case i get the 2nd, 3rd and 4th number of my Customer ID.
But how can i do this, if i want the 2nd, 3rd and 4th number of a column.
Like this one.
I have: Mercedes_02352
Audi_03555
and now i want to filter this data.frame to
235
355
can you
2018 Mar 29
2
Possible `substr` bug in UTF-8 Corner Case
I think there is a memory bug in `substr` that is triggered by a UTF-8 corner case: an incomplete UTF-8 byte sequence at the end of a string.? With a valgrind level 2 instrumented build of R-devel I get:
> string <- "abc\xEE"??? # \xEE indicates the start of a 3 byte UTF-8 sequence
> Encoding(string) <- "UTF-8"
> substr(string, 1, 10)
==15375== Invalid read of
2020 Jun 26
2
Error in substring: invalid multibyte string
Hi all,
I'm getting the following error from substring:
> substr("<I>Jens Oehlschl\xe4gel-Akiyoshi", 1, 100)
Error in substr("<I>Jens Oehlschl\xe4gel-Akiyoshi", 1, 100) :
invalid multibyte string at '<e4>gel-A<6b>iyoshi'
Is that normal / intended? I've tried setting the Encoding/locale to
Latin-1/UTF-8 but that does not help. nchar
2020 Jun 27
1
Error in substring: invalid multibyte string
Thanks for the quick response Ivan. readLines with encoding='latin1' works
for me (on Ubuntu).
However I was more concerned with the inconsistency in results between
substr and regexpr. I was expecting that if one of them errors because of
an unknown encoding then the other should as well. Even better, if regexpr
works, why shouldn't substr work as well?
Incidentally the analogous
2019 Dec 19
1
ALTREP string methods for substr and nchar
A useful extension of ALTREP is having two new string methods which
return the number of characters of a given string element and to
return a substring of an element.
Having these methods would allow retrieving these values without
needing to create a CHARSXP for the full element data, which could
potentially be costly for long elements.
For example say you have an ALTREP altstring vector where
2011 Jul 07
1
Substring a column vector
How to substring the following vector (in data frame b)
>b
a
11
12
1234
1245
124567
126786
145769
such that:
a1??? a2
1???? 1
1???? 2
12??? 23
12??? 34
124?? 567
126???787
145???769 ?
I tried logical commands with substr() did not work out.
2010 Apr 30
2
drop last character in a names'vector
Hi, i have a vector filled with names:
[1] Alvaro Adela ...
[25] Beatriz Berta ...
...
[100000] ...
I would like to drop last character in every name.
I use the next program:
for (i in 1:100000) {
? ? ? ? ? ? ? ? ? ? ? ? ? largo <- nchar(names[i]-1)
? ? ? ? ? ? ? ? ? ? ? ? ? names[i] <- substring (names[i],1,largo]
? ? ? ? ? ? ? ? ? ? ? ? ?}
Is another and faster way of do it?
Thanks,
2001 Feb 14
2
assignment function
Hi,
I am trying to create the assignment function:
"substring<-" <- function(text, first, last=100000, sub) {
if(is.character(first)) {
if(!missing(last)) stop('wrong # arguments')
return(sedit(text, first, sub))
}
lf <- length(first)
if(length(text)==1 && lf > 1) {
if(missing(last)) last <- nchar(text)
last <- rep(last,
2009 Aug 11
1
Passing a list object to lapply
Hello,
I'm having difficulty passing an object name to a lapply function. Can
somebody tell me the trick to make this work?
#Works
T13702 <- TRACKDATA[["13702.xls"]][["data"]]
min(unlist(lapply(list(T13702), function(x) mdy.date(x[1, 2], x[1, 1],
x[1, 3]))))
16553
#Works
d<-2
assign(paste("T",substr(names(TRACKDATA)[d],1,(nchar(names(TRACKDATA)[d]
2011 Sep 29
2
String manipulation with regexpr, got to be a better way
Help-Rs,
I'm doing some string manipulation in a file where I converted a string date in mm/dd/yyyy format and returned the date yyyy.
I've used regexpr (hat tip to Gabor G for a very nice earlier post on this function) in steps (I've un-nested the code and provided it and an example of what I did below. My question is: is there a more efficient way to do this. Specifically is
2020 Oct 23
2
How to shade area between lines in ggplot2
Thank you, but this split the area into two and distorts the shape of
the plot. (compared to
```
p + geom_abline(slope = slope_1, intercept = intercept_1 - 1/w[2],
linetype = "dashed", col = "royalblue") +
geom_abline(slope = slope_1, intercept = intercept_1 + 1/w[2],
linetype = "dashed", col = "royalblue")
```
Why there
2011 Dec 04
2
Extract last 3 characters from numeric vector
Hi all,
I have a numeric vector with 1 decimal place, and I'd like to extract
the last 3 characters, including the decimal point. The vector ranges
from 0 to 20.
x <- round(runif(100)*20, digits=1)
Some of numbers have 3 characters, and some have 4. I've read up on
the substr() function but that extracts characters based on exact
positions. How can I extract just the last 3
2011 Nov 15
1
Problem with substr
Hi, everyone
When I ran this cript, There is Error in substring(tmp.subject, tmp.end[ex]
+ 1, tmp.start[ex + 1] - 1) :
invalid substring argument(s)
Could someone figure out what the problem is?
for(i in 1:length(genebody[,1])){
tmp.id<-as.vector(genebody[i,1]) # get gene id
tmp.subject<-as.vector(genebody[i,2]) # get gene sequence
2020 Oct 26
0
How to shade area between lines in ggplot2
Hi
Put fill outside aes
p+geom_ribbon(aes(ymin = slope_1*x + intercept_1 - 1/w[2],
ymax = slope_1*x + intercept_1 + 1/w[2]), fill = "blue", alpha=0.1)
The "hole" is because you have two levels of data (red and blue). To get rid
of this you should put new data in ribbon call.
Something like
newdat <- trainset
newdat$z <- factor(0)
p+geom_ribbon(data=newdat, aes(ymin =
2003 Jul 21
1
Inconsistent handling of character NA?
[R 1.7.1 on Windows XP Pro]
Since R allows missing values for character variables, why
are NA's not propagated by character manipulation functions?
For example:
> temp <- c("a", NA)
> temp
[1] "a" NA
> is.na(temp)
[1] FALSE TRUE
> paste(temp[1], temp[2])
[1] "a NA"
> substr(temp, 1, 1)
[1] "a" "N"
>
2020 Oct 23
2
How to shade area between lines in ggplot2
also from this site: https://plotly.com/ggplot2/geom_ribbon/
I get the answer is geom_ribbon but I am still missing something
```
#! plot
p = ggplot(data = trainset, aes(x=x, y=y, color=z)) +
geom_point() + scale_color_manual(values = c("red", "blue"))
# show support vectors
df_sv = trainset[svm_model$index, ]
p = p + geom_point(data = df_sv, aes(x=x, y=y),
2020 Oct 31
2
fast way to find most common value across columns dataframe
As usual, a web search ("find statistical mode in R") brought up something
that is possibly useful -- Did you try this before posting? If not, please
do so in future and let us know what your results were if you subsequently
post here.
Here's what SO suggested:
Mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
# ergo: