similar to: Basic data structures

Displaying 20 results from an estimated 10000 matches similar to: "Basic data structures"

2008 Nov 29
2
Using grep() to subset lines of text
I have two vectors, a and b. b is a text file. I want to find in b those elements of a which occur at the beginning of the line in b. I have the following code, but it only returns a value for the first value in a, but I want both. Any ideas please. a = c(2,3) b = NULL b[1] = "aaa 2 aaa" b[2] = "2 aaa" b[3] = "3 aaa" b[4] = "aaa 3 aaa"
2011 Feb 01
3
R string help
Dear R guru: If I got a variable aaa<- "up.6.11(16)" how can I extract 16 out of the bracket? I could use substr, e.g. substr(aaa, start=1, stop=2) [1] "up" But it needs start and stop, what if my start or stop is not fixed, I just want the number inside the bracket, how can I achieve this? Many thanks yan
2010 May 05
1
extracting a matched string using regexpr
Given a text like I want to be able to extract a matched regular expression from a piece of text. this apparently works, but is pretty ugly # some html test<-"</tr><tr><th>88958</th><th>Abcdsef</th><th>67.8S</th><th>68.9\nW</th><th>26m</th>" # a pattern to extract 5 digits > pattern<-"[0-9]{5}" #
2009 Feb 25
3
regexp capturing group in R
Hello, Newbie question: how do you capture groups in a regexp in R? Let's say I have txt="blah blah start=20080101 end=20090224". I'd like to get the two dates start and end. In Perl, one would say: my ($start,$end) = ($txt =~ /start=(\d{8}).*end=(\d{8})/); I've tried: txt <- "blah blah start=20080101 end=20090224" m <-
2006 Jul 23
3
RfW 2.3.1: regular expressions to detect pairs of identical word-final character sequences
Dear all I use R for Windows 2.3.1 on a fully updated Windows XP Home SP2 machine and I have two related regular expression problems. platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor
2010 Feb 18
3
parsing strings between [ ] in columns
Dear all, I have a data.frame with a column like the x shown below myDF<-data.frame(cbind(x=c("[[1, 0, 0], [0, 1]]", "[[1, 1, 0], [0, 1]]","[[1, 0, 0], [1, 1]]", "[[0, 0, 1], [0, 1]]"))) > myDF x 1 [[1, 0, 0], [0, 1]] 2 [[1, 1, 0], [0, 1]] 3 [[1, 0, 0], [1, 1]] 4 [[0, 0, 1], [0, 1]] As you can see my x column is composed of
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
2010 Aug 22
4
how to implement string pattern extraction in R
Hi, In perl, to get a substring matching a particular pattern can be implemented like the following example: $x = "AAAA.txt"; if ($x=~ /(.*?)\.txt/){ $prefix = $1; } So how to do the same thing in R? Can someone provide me the code sample? Thanks much in advance. -- Waverley @ Palo Alto
2010 Oct 26
2
Formatting durations
Hi, I am working with a dataset for sometime and I need some help in parsing some data. There is a column called "Duration" which has data like following: 2 minutes => 120 2 min => 120 10 seconds =>10 2 hrs =>7200 2-3 minutes => 150 or 120 5 minutes (when i arrived => 300 Flyby approx 20 sec. => 20 felt like 10 mins but tim => 600 I need to convert them to
2009 Apr 15
2
Split string
> (FICB[,"temp"]) [1] "0.30" "0.55" "0.45" "2.30" "0.45" "0.30" "0.25" "0.30" "0.30" "1.05" "1.00" "1.00" [13] "0.30" "0.30" "0.30" "0.55" "0.30" "0.30" "0.30" "0.25" "1.00"
2009 Mar 03
4
regular expression question
can someone show me how to use a regular expression to break the string at the bottom up into its three components : (-0.791,-0.263] (-38,-1.24] (0.96,2.43] I tried to use strplit because of my regexpitis ( it's not curable. i've been to many doctors all over NYC. they tell me there's no cure ) but it doesn't work because there also dots inside the brackets. Thanks.
2008 Nov 02
5
R newbie: how to replace string/regular expression
Hello; I am a R newbie and would like to know correct and efficient method for doing string replacement. I have a large data set, where I want to replace character "M", "b", and "K" (currency in Million, Billion and K) to millions. That is 209.7B with (209.7 * 10e6) and 100.00K with (100.00 *1/100) and etc.. d <- c("120.0M", "11.01m",
2008 Aug 12
2
perl expression question
I have a string such as fileName<-"Agg.20.20.20-all-01". All I want to do is pull the "20.20.20" and the "all" as strings. Obviously, they aren't always those values. The "20.20.20" can be "30.30.30" but it's always after the . which is next to the second g in Agg and it's always the same length. The all might not always be
2006 Sep 25
2
Splitting a character variable into a numeric one and a character one?
Hi All, I have a data with a variable like this: Column 1 "123abc" "12cd34" "1e23" ... Now I want to do an operation that can split it into two variables: Column 1 Column 2 Column 3 "123abc" 123 "abc" "12cd34" 12 "cd34" "1e23" 1
2008 Nov 28
3
regexp help needed
Hello, I have a vector of dates and I would like to grep the year component from this vector (= all digits after the last punctuation character) dates <- c("28.7.08","28.7.2008","28/7/08", "28/7/2008", "28/07/2008", "28-07-2008", "28-07-08") the resulting vector should look like "08" "2008"
2009 Dec 28
3
apply loop - using/providing a data frame to loop over
Hi, I want to extract individual names from a single string that contains all names. My problem is not the extraction itself, but the looping over the extraction start and end points, which I try to realize with apply. #Say, I have a string with names. authors=c("Schleyer T, Spallek H, Butler BS, Subramanian S, Weiss D, Poythress ML, Rattanathikun P, Mueller G") #Since I only want the
2006 Nov 07
1
Gregexpr - extract results with lapply
Gregexpr - extract results with lapply Hello, I need to extract sequences of three upper case letters in a string. In other words, in this string: str <-c("ABC", "this WOUld be gOOD") The result I'm looking for is ABC WOU OOD. With gregexpr, I can get the position and length of the sequences gregexpr('[A-Z]{3}',str,perl=TRUE) [[1]] [1] 1
2008 Sep 18
3
character position
Hi, I'm not being able to capture a position of a 'string' in a character string. In this example: 'There are 20 species in this grid' I would like to capture the string (number) after 'are' and before 'species'. Consider they do not change. I wouldn't like to use substr because stop position may change. Thanks Paulo
2010 Feb 08
2
the hat ^ in regular expression
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible URL : <https://stat.ethz.ch/pipermail/r-help/attachments/20100208/52a6d080/attachment.pl>
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, >