similar to: Q. About String indexing

Displaying 20 results from an estimated 10000 matches similar to: "Q. About String indexing"

1999 Dec 18
1
strsplit does not conform to documentation (PR#379)
Description: Split the Strings in `x' into substrings according to the presence of substring `split' within them. -------------------- > strsplit("acbdefgSPLIThigkilmnSpPqrst","SPLIT") [[1]] [1] "acbdefg" "higkilmn" "p" "qrst" -------------------- Apparently, it will Split the Strings in `x' into
2012 Feb 08
4
"unsparse" a vector
Suppose I have a vector of strings: c("A1B2","A3C4","B5","C6A7B8") [1] "A1B2" "A3C4" "B5" "C6A7B8" where each string is a sequence of <column><value> pairs (fixed width, in this example both value and name are 1 character, in reality the column name is 6 chars and value is 2 digits). I need to
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
2009 Apr 10
4
split a character variable into several character variable by a character
Dear Mao Jianfeng, "r-help-owner" is not the place for help, but: r-help at r-project.org (CC-ed here) In any case, strsplit() does the job, i.e.: > unlist(strsplit("BCPy01-01", "-")) [1] "BCPy01" "01" You can work with the whole variable, like: splitpop <- strsplit(df1$popcode, "-") then access the first part with >
2009 Sep 25
7
Spliting columns, strings or reg exp returning substrings
Currently as the first column in a data frame I have string values in the format xx_yy - I want to create a new column with just the substring xx (for each row in turn). Three possible ways to do this might be (1) split the string by '_' using strsplit and paste the first of the resulting variables into a new column, but I have been unable to do this for each row of my data frame in turn
2005 Oct 28
3
splitting a character field in R
Dear R users, I have a dataframe with one character field, and I would like to create two new fields (columns) in my dataset, by spliting the existing character field into two using an existing substring. ... something that in SAS I could solve e.g. combining substr(which I am aware exist in R) and "index" for determining the position of the pattern within the string. e.g. if my
2011 Jun 18
3
how to subtract one string from another in R
Dear R Group Here is what i am trying to do.. but couldnt figure out how.. string<-"ABC DEFG HIJKLM NOPQ RSTUV WXY" string1<-substr(string,1,4) I want to create an R object string 2 ( following the logic shown).. R does not allow string subtraction.. any suggestions how to achieve this? string2<-string-string1 (it should now hold "DEFG HIJKLM NOPQ RSTUV WXY" I
2009 Dec 09
4
binary string conversion to a vector (PR#14120)
Full_Name: Franc Brglez Version: R 2.9.1 GUI 1.28 Tiger build 32-bit (5444) OS: MacOSX -- 10.6.2 Submission from: (NULL) (24.148.163.114) I am demonstrating what may be a bug or my lack of experience. Please review as it would help to hear from someone. MANY THANKS -- Franc Brglez The function "binS2binV" returns what I consider a wrong value -- see the terminal output binS2binV =
2009 Jul 08
5
R regular expression to extract words with the query string.
Hi, Is there a way in R to get the string which matches the expression, where the expression is a substring of the parent string. Lets say, I have $i <- "transcript:ENST0000112334 pid:ENSP000012345" What I need is the string "pid:ENSP000012345" from $i using the query "ENSP". Appreciate your comments. Praveen Surendran School of Medicine and
2004 Mar 24
1
string problems ( grep and regepxr)
Recently working with strings and data I have found a small problem. Windows XP R 1.8.1 Reading data from a "txt file" with readLine. finding a specific line with "grep" command, all OK. but here comes the problem... After finding the correct line(s) i need to find a substring inside each string. In this case "tabs" I think it represented by "\t" in the
2009 Oct 23
2
splitting a vector of strings...
Quick question -- if I have a vector of strings that I'd like to split into two new vectors based on a substring that is inside of each string, what is the most efficient way to do this? The substring that I want to split on is multiple characters, if that matters, and it is contained in every element of the character vector. --j -- Jonathan A. Greenberg, PhD Postdoctoral Scholar
2004 Oct 20
7
Q about strsplit and regexp
Dear R-help, This one is probably a piece of cake for regexp masters. I'd like to split a character vector (for simplicity, say of length one for now) that contains fields that are delimited by arbitrary number of white spaces (e.g., " a b c "). How do I get the character vector that contain the fields? In the example I gave, I've tried: > strsplit(" a b c
2006 Jul 17
10
String manipulation and formatting
I'm trying to write a simple function that does the following: [command] xify(5.2) [output] XXX.XX [command] xify(3) [output] XXX Any simple solutions (without using python/perl/unix script/...)? Thanks, Saghir --------------------------------------------------------- Legal Notice: This electronic mail and its attachments are i...{{dropped}}
2011 Apr 11
1
Getting many substrings but only loading the original string one time.
Hi All, I'm looking for a way to get many substrings from a longer string and then stitch them together. But, since the longer string is really, really long (like 250 MB long), I don't want to do this in a loop and load and re-load the longer string many times. Does anybody have an idea? Maybe I could pass in two vectors (the first would have the starting coordinates, and the second
2003 May 22
4
grep, gsub, sub have problems with NA values (PR#3078)
In a string context, grep, gsub, sub are improperly treating NA (missing) as the string "NA", and returning unexpected results > grep("A", c(NA,"NA")) [1] 1 2 # expected: # [1] 2 > gsub("A", "X", c(NA,"NA")) [1] "NX" "NX" # expected # [1] NA "NX" > sub("A", "X",
2011 Jul 05
2
Stuck ...can't get sapply and xmlTreeParse working
Can't seem to get the code below working. It gets stuck on line 24 inside the function hm; comments show the line in question. The function hm is called by sapply and is at the bottom of the code. Other stuff above line 24 works correctly including the first couple of lines of the function hm. Should I be using a different apply function or am I doing something wrong with xmlTreeParse ?
2007 Aug 02
4
Finding multiple characters in the same string
Hi I have this problem where I need to find if there is any numbers in a string, this is no problem if theres only one number per string. I would then simply use the regexpr() funtion togheter with the substring function to extract the number. But regexpr only picks one number per string either from the beginning or the end, but not multiple. Can this be done? And how for example My string <-
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
2011 Oct 05
3
R CMD check
Dear R-Group, I have a function that sorts a data frame and oneo of the lines in the function is: vars <- unlist(strsplit(formc, "[\\+\\-]")) The function works fine and the above line is always reached. However, when I include the function in a package and run "R CMD check pkgname" it gives this error message: '\+' is an unrecognized escape in character
2005 Oct 20
4
read.fwf doesn't work with header = TRUE (PR#8226)
Full_Name: Emmanuel Paradis Version: 2.1.1 OS: Linux Submission from: (NULL) (193.49.41.105) read.fwf(..., header = TRUE) does not work properly since: 1/ the original header is printed on the console and not in FILE; 2/ the different 'parts' of the header should be separated with tabs to work with the call to read.table. Here is a suggested fix for src/library/utils/R/read.fwf.R: