Re: [R] Split strings based on multiple patterns

2016-10-19 Thread Joe Ceradini
Thanks for the additional approach, Greg. I had success with Gabor's recommendation but will take a look at gsubfn as well. Joe On Wed, Oct 19, 2016 at 10:19 AM, Greg Snow <538...@gmail.com> wrote: > I would suggest looking at the strapply function in the gsubfn > package. That gives you more f

Re: [R] Split strings based on multiple patterns

2016-10-19 Thread Greg Snow
I would suggest looking at the strapply function in the gsubfn package. That gives you more flexibility in specifying what to look for in the structure of the data, then extract only those pieces that you want. On Fri, Oct 14, 2016 at 5:16 PM, Joe Ceradini wrote: > Afternoon, > > I unfortunatel

Re: [R] Split strings based on multiple patterns (plain text)

2016-10-15 Thread Joe Ceradini
Thank you David Wolfskill, David Winsemius, and Gabor! All very helpful and interesting fixes for the problem (compiled below)! Now I will see which one works best on the 944 rows that each have a cell of smooshed attributes...the attribute names should be the same in all the rows, if there is any

Re: [R] Split strings based on multiple patterns

2016-10-15 Thread Gabor Grothendieck
Replace newlines and colons with a space since they seem to be junk, generate a pattern to replace the attributes with a comma and do the replacement and finally read in what is left into a data frame using the attributes as column names. (I have indented each line of code below by 2 spaces so if

Re: [R] Split strings based on multiple patterns (plain text)

2016-10-14 Thread David Winsemius
> On Oct 14, 2016, at 6:53 PM, Joe Ceradini wrote: > > Hopefully this looks better. I did not realize gmail default was html. > > I have a dataframe with a column that has many field smashed together. > I need to split the strings in the column into separate columns based > on patterns. > > Ex

Re: [R] Split strings based on multiple patterns (plain text)

2016-10-14 Thread Joe Ceradini
should be strsplit(ugly, attributes) not strplit(ugly, attributes) On Fri, Oct 14, 2016 at 7:53 PM, Joe Ceradini wrote: > Hopefully this looks better. I did not realize gmail default was html. > > I have a dataframe with a column that has many field smashed together. > I need to split the str

[R] Split strings based on multiple patterns (plain text)

2016-10-14 Thread Joe Ceradini
Hopefully this looks better. I did not realize gmail default was html. I have a dataframe with a column that has many field smashed together. I need to split the strings in the column into separate columns based on patterns. Example of a string that needs to be split: ugly <- c("Water temp:14: F

Re: [R] Split strings based on multiple patterns

2016-10-14 Thread David Winsemius
> On Oct 14, 2016, at 4:16 PM, Joe Ceradini wrote: > > Afternoon, > > I unfortunately inherited a dataframe with a column that has many fields > smashed together. My goal is to split the strings in the column into > separate columns based on patterns. > > Example of what I'm working with: > >

[R] Split strings based on multiple patterns

2016-10-14 Thread Joe Ceradini
Afternoon, I unfortunately inherited a dataframe with a column that has many fields smashed together. My goal is to split the strings in the column into separate columns based on patterns. Example of what I'm working with: ugly <- c("Water temp:14: F Waterbody type:Permanent Lake/Pond: Water pH:

Re: [R] Split Strings

2016-01-18 Thread Miluji Sb
Thank you everyone for the codes and the link. They work well! Mr. Lemon, thank you for the detailed code and the explanations. I appreciate it. One thing though, in the last line sapply(split_strings,fill_strings,list(max_length,element_sets)) should it be unlist instead of list - I get this er

Re: [R] Split Strings

2016-01-18 Thread Jim Lemon
Hi Miluji, While the other answers are correct in general, I noticed that your request was for the elements of an incomplete string to be placed in the same positions as in the complete strings. Perhaps this will help: strings<-list("pc_m2_45_ssp3_wheat","pc_m2_45_ssp3_wheat", "ssp3_maize","m2_wh

Re: [R] Split Strings

2016-01-17 Thread William Michels via R-help
> str_1 <- list("pc_m2_45_ssp3_wheat", "pc_m2_45_ssp3_wheat", "ssp3_maize", > "m2_wheat") > str_2 <- strsplit(unlist(str_1), "_") > max.length <- max(sapply(str_2,length)) > str_3 <- lapply(lapply(str_2, unlist), "length<-", max.length) > str_3 See: http://stackoverflow.com/questions/27995639/i-

Re: [R] Split Strings

2016-01-17 Thread Adrian Dușa
Try this: mylist <- list("pc_m2_45_ssp3_wheat", "pc_m2_45_ssp3_wheat", "ssp3_maize", "m2_wheat") mylist <- lapply(mylist, function(x) unlist(strsplit(x, split="_"))) allstrings <- unique(unlist(mylist)) lapply(mylist, function(x) allstrings[match(allstrings, x)]) [[1]] [1] "pc""m2""45"

[R] Split Strings

2016-01-17 Thread Miluji Sb
I have a list of strings of different lengths and would like to split each string by underscore "_" pc_m2_45_ssp3_wheat pc_m2_45_ssp3_wheat ssp3_maize m2_wheat I would like to separate each part of the string into different columns such as pc m2 45 ssp3 wheat But because of the different length

Re: [R] split strings in a vector and convert it to a data.frame

2010-02-09 Thread Gabor Grothendieck
On Tue, Feb 9, 2010 at 6:46 PM, Martin Batholdy wrote: > hi, > > I have a vector full of strings like; > > > xy_100_ab       xy_101_ab       xy_102_ab       xy_103_ab > > > I want to seperate each string in three pieces and the separator should be > the "_" > > at the end I want a data.frame like

Re: [R] split strings in a vector and convert it to a data.frame

2010-02-09 Thread David Winsemius
On Feb 9, 2010, at 6:46 PM, Martin Batholdy wrote: hi, I have a vector full of strings like; xy_100_ab xy_101_ab xy_102_ab xy_103_ab I want to seperate each string in three pieces and the separator should be the "_" at the end I want a data.frame like: column1 column

Re: [R] split strings in a vector and convert it to a data.frame

2010-02-09 Thread Jorge Ivan Velez
Hi Martin, Here is a sugestion: string <- c("xy_100_ab", "xy_101_ab","xy_102_ab","xy_103_ab") out <- data.frame( do.call( rbind, strsplit( string, '_' ) ) ) names(out) <- paste('column',1:3,sep="") out HTH, Jorge On Tue, Feb 9, 2010 at 6:46 PM, Martin Batholdy <> wrote: > hi, > > I have a vect

[R] split strings in a vector and convert it to a data.frame

2010-02-09 Thread Martin Batholdy
hi, I have a vector full of strings like; xy_100_ab xy_101_ab xy_102_ab xy_103_ab I want to seperate each string in three pieces and the separator should be the "_" at the end I want a data.frame like: column1 column2 column3 xy 100 ab xy

Re: [R] split strings

2009-05-28 Thread Wacek Kusnierczyk
(diverted to r-devel, a source code patch attached) Wacek Kusnierczyk wrote: > Allan Engelhardt wrote: > >> Immaterial, yes, but it is always good to test :) and your solution >> *is* faster and it is even faster if you can assume byte strings: >> > > :) > > indeed; though if the speed is

Re: [R] split strings

2009-05-27 Thread Monica Pisica
ndi...@gmail.com > Date: Tue, 26 May 2009 16:40:21 -0400 > Subject: Re: [R] split strings > To: waclaw.marcin.kusnierc...@idi.ntnu.no > CC: pisican...@hotmail.com; r-help@r-project.org > > Although speed is really immaterial here this is likely > to be faster than all sho

Re: [R] split strings

2009-05-27 Thread Wacek Kusnierczyk
Allan Engelhardt wrote: > Immaterial, yes, but it is always good to test :) and your solution > *is* faster and it is even faster if you can assume byte strings: :) indeed; though if the speed is immaterial (and in this case it supposedly was), it's probably not worth risking fixed=TRUE removing

Re: [R] split strings

2009-05-26 Thread Allan Engelhardt
ne-pass, no perl'=sub('.*//(.*)[.]tif$', '\\1', strings, perl=FALSE), 'two-pass, no perl'=sub('.tif$', '', basename(strings), perl=FALSE)) # 1one-pass, perl 3.391 # 2two-pass, perl 4.944 # 3 one-pass, no perl 18.836 # 4 two

Re: [R] split strings

2009-05-26 Thread Gabor Grothendieck
basename(strings), perl=FALSE)) >    # 1    one-pass, perl   3.391 >    # 2    two-pass, perl   4.944 >    # 3 one-pass, no perl  18.836 >    # 4 two-pass, no perl   5.191 > > vQ > > >> >> Monica >> >> >>

Re: [R] split strings

2009-05-26 Thread Wacek Kusnierczyk
=FALSE), 'two-pass, no perl'=sub('.tif$', '', basename(strings), perl=FALSE)) # 1one-pass, perl 3.391 # 2two-pass, perl 4.944 # 3 one-pass, no perl 18.836 # 4 two-pass, no perl 5.191 vQ > > Monica > > --

Re: [R] split strings

2009-05-26 Thread Monica Pisica
; From: waclaw.marcin.kusnierc...@idi.ntnu.no > To: pisican...@hotmail.com > CC: r-help@r-project.org > Subject: Re: [R] split strings > > Monica Pisica wrote: >> Hi everybody, >> >> I have a vector of characters and i would like to extract certain parts. My >> vector is named

Re: [R] split strings

2009-05-26 Thread Wacek Kusnierczyk
Monica Pisica wrote: > Hi everybody, > > I have a vector of characters and i would like to extract certain parts. My > vector is named metr_list: > > [1] "F:/Naval_Live_Oaks/2005/data//BE.tif" > [2] "F:/Naval_Live_Oaks/2005/data//CH.tif" > [3] "F:/Naval_Live_Oaks/2005/data//CRR.tif" > [4]

Re: [R] split strings

2009-05-26 Thread Gabor Grothendieck
Try this: sub(".tif$", "", basename(metr_list)) On Tue, May 26, 2009 at 9:27 AM, Monica Pisica wrote: > > Hi everybody, > > I have a vector of characters and i would like to extract certain parts. My > vector is named metr_list: > > [1] "F:/Naval_Live_Oaks/2005/data//BE.tif" > [2] "F:/Naval_Li

Re: [R] split strings

2009-05-26 Thread Ronggui Huang
They look like file path, so you can make use of basename() first, then use gsub to strip the suffix. > x<-c("F:/Naval_Live_Oaks/2005/data//BE.tif","F:/Naval_Live_Oaks/2005/data//CH.tif") > x2<-sapply(x,basename,USE.NAMES=FALSE) > gsub("[.].{1,}$","",x2) [1] "BE" "CH" Ronggui 2009/5/26 Monica Pi

[R] split strings

2009-05-26 Thread Monica Pisica
Hi everybody, I have a vector of characters and i would like to extract certain parts. My vector is named metr_list: [1] "F:/Naval_Live_Oaks/2005/data//BE.tif" [2] "F:/Naval_Live_Oaks/2005/data//CH.tif" [3] "F:/Naval_Live_Oaks/2005/data//CRR.tif" [4] "F:/Naval_Live_Oaks/2005/data//HOME.t