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
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
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
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
> 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
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
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
> 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:
>
>
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:
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
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
> 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-
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"
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
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
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
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
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
(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
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
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
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
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
>>
>>
>>
=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
>
> --
; 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
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]
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
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
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
29 matches
Mail list logo