similar to: Extract last 3 characters from numeric vector

Displaying 20 results from an estimated 10000 matches similar to: "Extract last 3 characters from numeric vector"

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,
2010 Jan 12
5
Drop last numeral
Hello all, Frustrated and i know you can help I need to drop the last numeral of each of my values in my data set. So for the following i have tried the ?substring but since i have to specify the length, but because my data are of varying lengths it doenst work so well Data<-c("1131", "1132", "1731" ,"1732" ,"1821" ,"1822",
2005 Oct 31
6
getting last 2 charcters of a string, other "text" functions?
I wish to obtain the right-most n characters of a character string? What is the appropriate function? --------------------------------- [[alternative HTML version deleted]]
2011 Sep 30
2
Overlapping plot in lattice
Hi all, I was wondering if there's an equivalent to par(new=T) of the plot function in lattice. I'm plotting an xyplot, and I would like to highlight one point by plotting that one point again using a different symbol. For example, where 6 is highlighted: plot(1:10, xlim=c(0,10), ylim=c(0,10)) par(new=T) plot(6,6, xlim=c(0,10), ylim=c(0,10), pch=16) Is there a way to do this in lattice?
2010 Jun 14
3
remove last char of a text string
Dear R experts, is there a simple way to remove the last char of a text string? substr() function use as parameter start end only... but my strings are of different length... 01asap05a -> 01asap05 02ee04b -> 02ee04 Thank you all, Gianandrea -- View this message in context: http://r.789695.n4.nabble.com/remove-last-char-of-a-text-string-tp2254377p2254377.html Sent from the R help mailing
2009 Oct 19
2
Using grep to determine value of last letter...
I am currently being defeated by grep. I am attempting to determine the value of the last letter of a character string. An example of my data set is shown below. Regarding the codes, I would like to identify the value of the last character and then take the appropriate action, e.g. If the value is L then label UL rating XXX It the value is F then label UL rating YYY ... I assume it will be
2007 Oct 15
4
Get the last 3 chars of a string
I want to extract the last 3 letters of a string. So far, I've done this: > symbol = 'XYZ.VX" > substr(symbol,nchar(symbol)-2,nchar(symbol)) [1] ".VX" It works, but the code looks UGLY as hell. Am I missing something? Or is this the way it's supposed to be? Thanks, Sergio On 10/15/07, pintinho <diego at bpgomes.com> wrote: > > Hi everyone, >
2011 Jan 16
2
xyplot: modify axis tick marks
Hi, I would like to plot time against rainfall data (data is at the end) using xyplot. The basic code looks like this: xyplot(rainfall~time, type="a") When I do this, the graph looks ok except that the x-axis has too many values. I would just like to display the years and not the months on the x-axis. I've been fiddling around with 'scales', and read previous posts about
2009 Oct 25
1
rotate levelplot
Hi all, I have a matrix with 5 rows and 10 columns, which represent the grids on a rectangular map. I used the code below to plot, but it gives me the map with the 10 columns as y-axis, and the 5 rows as the x-axis, and the (0,0) point is at the usual bottom left hand corner. My map starts with the (0,0) at the top left hand corner. How can I rotate the map 90 degrees clockwise so the (0,0)
2018 Jan 21
3
substr gives empty output
Dear all, I have a string, let's say "testing", and I would like to extract in sequence each letter (character) from it. But when I use substr() I only properly get the first character, the rest is empty (""). What am I getting wrong? For example, I have this code: >>> x <- "testing" k <- nchar(x) for (i in 1:k) { y <- substr(x, i, 1)
2011 Feb 24
1
extract printed value from a function
Hello all, This shouldn't be difficult, but I am not able to extract a printed value from a function and assign it to an object. In my case, > library(DAAG) > twotPermutation(c(2,3,4),c(3,6,5),plotit=F) [1] 0.298 I would like to assign this result to an object. Thanks, Duarte
2010 May 15
1
Barchart reorder
Hi fellow R users, I have a dataset that looks something like this. species class abundance K 1 592 K 2 288 G 1 254 G 2 239 C 2 173 D 2 123 E 3 89 F 2 87 B 2 86 H 2 82 I 1 79 J 2 76 B 1 73 D 3 72 A 2 62 L 2 58 I want to plot a stacked barchart. species is the x-axis, abundance is y-axis, and class will appear as the stacks in different colours. I need the species to be displayed in descending
2008 Oct 20
2
Extracting variables with a given prefix in the parent environment
hi, get.vars.name.prefix<-function(prefix){ result<-list() len<-nchar(prefix) var.names<-ls(name=1,pattern=prefix) #name=1 probably wrong option print(var.names) for(i in 1:length(var.names)){ name<-var.names[i] field<-substr(name,len+1,nchar(name)) result[[field]]<-get(name) } result } for example x.1<-1 x.2<-2 get.vars.name.prefix("x.") should
2010 May 28
1
Match 2 vectors
Hi, I have 2 dataframes of unequal length, and I would like to match a factor to them so that both dataframes will have the same number of rows. example: # create the 2 dataframes with unequal length data1 <- data.frame(letters, 1:26)[-c(5,10,19:21),] data2 <- data.frame(letters, 1:26)[-c(6,9,15:18),] data2a <- match(data1[,1], data2[,1]) data2b <- data2[data2a,] When I match
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
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()
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
2007 Jun 11
2
selecting characters from a line of text
Is there a way in R to select certain characters from a line of text? I have some data that is presently in a large number of text files, and I would like to be able to select elements of each text file (elements are always on the same line, in the same position) and organize them into a table. Is there a tool to select text in this way in R? What I am looking for would be somewhat similar to
2010 May 31
1
Replacing NAs with 0 for a list of data frames
Hi, I have a list of 100 data frames, each data frame has 50 obs of 377 variables. I would like to replace all the NAs with 0 in all the dataframes. Should I have a for loop for every data frame? Below is an extract of how the data looks like. List of 100 $ :'data.frame': 50 obs. of 377 variables: ..$ ACHRPO: int [1:50] NA NA NA NA NA NA NA NA NA NA ... ..$ ACTEEX: int [1:50] NA
2010 May 23
2
Subsetting with a list of vectors
Hi, I have a dataset that looks like the one below. data plot plantno. species H 31 ABC D 2 DEF Y 54 GFE E 12 ERF Y 98 FVD H 4 JKU J 7 JFG A 55 EGD . . . . . . .