> correct example is
> >
> >
> > mydf <- data.frame(id_station = 1234, string_data = as.factor(2024, 12,
> > 1, 0, 0), rainfall_value= 55)
> >
> >
> > In this case mydf$string_data is a factor, but of length 1 (and not 5
> > like in the initial example
-help@r-project.org
Subject: Re: [R] split a factor into single elements
[External Email]
Hi,
why would this simple procedure not work?
--- snip ---
mydf <- data.frame(id_station = 1234, string_data = c(2024, 12, 1, 0, 0),
rainfall_value= 55)
mydf$string_data <- as.factor(mydf$strin
s.numeric(mydf[[new_var_name]])
> }
> # remove trash
> mydf <- mydf[,-4]
> # Provide more useful names
> colnames(mydf) <- c("id_station", "string_data", "rainfall_mm", "Year",
> "Month", "Day", "hour", "mi
Provide more useful names
colnames(mydf) <- c("id_station", "string_data", "rainfall_mm", "Year",
"Month", "Day", "hour", "minute")
Regards,
Tim
-Original Message-
From: R-help On Behalf Of Stefano Sofia
On 28/03/2024 7:48 a.m., Stefano Sofia wrote:
as.factor(2024, 12, 1, 0, 0)
That doesn't work. You need to put the numbers in a single vector as
Fabio did, or you'll see this:
Error in as.factor(2024, 12, 1, 0, 0) : unused arguments (12, 1, 0, 0)
Duncan Murdoch
p@R-project.org
Oggetto: Re: [R] split a factor into single elements
Non si ricevono spesso messaggi di posta elettronica da
dagostinof...@gmail.com. Informazioni sul perch� �
importante<https://aka.ms/LearnAboutSenderIdentification>
Hi Stefano,
maybe something like this can help you?
myfactor <
-mail: stefano.so...@regione.marche.it
---Oo-oO
Da: Fabio D'Agostino
Inviato: gioved� 28 marzo 2024 12:20
A: Stefano Sofia; r-help@R-project.org
Oggetto: Re: [R] split a factor into single elements
Non si ricevono
Hi Stefano,
maybe something like this can help you?
myfactor <- as.factor(c(2024, 2, 1, 0, 0))
# Convert factor values to integers
first_element <- as.integer(as.character(myfactor)[1])
second_element <- as.integer(as.character(myfactor)[2])
third_element <- as.integer(as.character(myfactor)[3])
Dear R-list users,
forgive me for this silly question, I did my best to find a solution with no
success.
Suppose I have a factor type like
myfactor <- as.factor(2024, 2, 1, 0, 0)
There are no characters (and therefore strsplit for eample does not work).
I need to store separately the 1st,
Dear Emily,
I have written a more robust version of the function:
extract.nonLetters = function(x, rm.space = TRUE, normalize=TRUE,
sort=TRUE) {
if(normalize) str = stringi::stri_trans_nfc(str);
ch = strsplit(str, "", fixed = TRUE);
ch = unique(unlist(ch));
if(sort) ch =
Dear Emily,
Using a look-behind solves the split problem in this case. (Note: Using
Regex is in most/many cases the simplest solution.)
str = c("leucocyten + gramnegatieve staven +++ grampositieve staven ++",
"leucocyten – grampositieve coccen +")
tokens = strsplit(str, "(?<=[-+])\\s++",
Since any space that follows 2 or 3 + signs (or - signs) also follows
a single + (or -), this can be done with positive look behind, which
may be a little simpler:
x <- c(
'leucocyten + gramnegatieve staven +++ grampositieve staven ++',
'leucocyten - grampositieve coccen +'
)
strsplit(x,
I always find regex puzzles amusing, so after changing the unicode
typo quotes and dashes to ascii, the following simple prescription,
similar to those proffered by others, seems to produce what you
requested with your example:
x <- c("leucocyten + gramnegatieve staven +++ grampositieve staven
rg
Subject: Re: [R] Split String in regex while Keeping Delimiter
I thought replacing the spaces following instances of +++,++,+,- with "\n" and
then reading with scan should succeed. Like Ivan Krylov I was fairly sure that
you meant the minus sign to be "-" rather than "
I thought replacing the spaces following instances of +++,++,+,- with "\n" and
then reading with scan should succeed. Like Ivan Krylov I was fairly sure that
you meant the minus sign to be "-" rather than "–", but perhaps your were using
MS Word as an editor which is inconsistent with effective
On Wed, 12 Apr 2023 08:29:50 +
Emily Bakker wrote:
> Some example data:
> “leucocyten + gramnegatieve staven +++ grampositieve staven ++”
> “leucocyten – grampositieve coccen +”
>
> I want to split the strings such that I get the following result:
> c(“leucocyten +”, “gramnegatieve staven
This seems to do the job but there are probably more elegant solutions:
f <- function(s) { sub("^ ","",unlist(strsplit(gsub("\\+ ","+@ ",s),"@"))) }
g <- function(s) { sub("^ ","",unlist(strsplit(gsub("- ","-@ ",s),"@"))) }
h <- function(s) { g(f(s)) }
To try it out:
s <- “leucocyten +
Hello List,
I have a dataset consisting of strings that I want to split while saving the
delimiter.
Some example data:
“leucocyten + gramnegatieve staven +++ grampositieve staven ++”
“leucocyten – grampositieve coccen +”
I want to split the strings such that I get the following result:
-project.org
> Subject: [R] split apply on multiple variables
>
>
> I am looking for a more general solution to below exercise.
>
> Thanks,
> Naresh
>
> library(plyr)
> mydf <- data.frame(
> date = rep(seq.Date(from = as.Date("2022-06-01"), by = 1, leng
Yes, you are right, it works fine when plotting on file.
Thank you!
On Thu, Oct 21, 2021 at 11:42 PM Bert Gunter wrote:
>
> The syntax is correct; the default margins are too large for your device.
>
> For example, using your split screen specs on the RStudioGD
>
> > split.screen(c(3, 1))
Hi Luigi,
Bert has identified the problem. If the ordinates in each row are the
same, you can save quite a bit of space by setting the left and right
margins to zero on all but the left plots in each row. This will jam
the plots together at the sides, but that may not matter to you.
Remember that
The syntax is correct; the default margins are too large for your device.
For example, using your split screen specs on the RStudioGD
> split.screen(c(3, 1)) # split display into 3 screens
[1] 1 2 3
>
> split.screen(c(1, 2), screen = 2) # split second screen into two columns
[1] 4 5
>
>
Hello,
I would like to draw 5 figures in the same plot. The layout is:
first row: 1 column
second row: 2 columns
third row: 2 columns
I have used split.screen:
```
> split.screen(c(3, 1)) # split display into 3 screens
[1] 1 2 3
> split.screen(c(1, 2), screen = 2) # split second screen
Perfect!
thank you
On Fri, Aug 6, 2021 at 4:17 PM Bill Dunlap wrote:
>
> unlist(strsplit(vect, "\n"))
>
> On Fri, Aug 6, 2021 at 7:13 AM Luigi Marongiu
> wrote:
>>
>> Hello,
>> I have a vector that contains some elements with concatenated values, such
>> as:
>> ```
>> > vect
>> [1] "name_1"
unlist(strsplit(vect, "\n"))
On Fri, Aug 6, 2021 at 7:13 AM Luigi Marongiu
wrote:
> Hello,
> I have a vector that contains some elements with concatenated values, such
> as:
> ```
> > vect
> [1] "name_1"
> [2] "name_2"
> [3] "name_3\nsurname_3"
> [4] "some other text\netc"
> ```
> How can I
Hello,
I have a vector that contains some elements with concatenated values, such as:
```
> vect
[1] "name_1"
[2] "name_2"
[3] "name_3\nsurname_3"
[4] "some other text\netc"
```
How can I create a new vector where each component is an element, such as:
```
> vect
[1] "name_1"
[2] "name_2"
[3]
On 2021-03-08 17:14 +0330, javad bayat wrote:
> Dear Rasmus;
> Many thanks. It works for me.
> Sincerely yours
Great :)
signature.asc
Description: PGP signature
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
Dear Javad,
data <- "Date Cases Country
2020-12-14 746 Country1
2020-12-15 324 Country1
2020-12-15 1 Country3
2020-12-13 298 Country2"
data <- read.table(text=data, header=T)
x <- reshape(
data=data,
timevar =
Dear R users;
Hi.
I have a problem with splitting dataframe into several.
I have a large dataframe (Length of 61000). It has 4 Columns as below:
"
Date Cases Country
12020-12-14 746Country1
22020-12-15 324
Thank you again for your help and giving me the opportunity to choose
the efficient method. For a small data set there is no discernable
difference between the different approaches. I will carry out a
comparison using the large data set.
On Wed, Sep 23, 2020 at 11:52 AM LMH wrote:
>
> Below
Below is a script in bash the uses the awk tokenizer to do the work.
This assumes that your input and output delimiter is space. The number of
consecutive delimiters in
the input is not important. This also assumes that the input file does not have
a header row. That
is easy to modify if you
What is the delimiter is in the input data? Is it tab, space, etc?
Is this going to be the same for the output data that you will use for R input?
LMH
Val wrote:
> Thank you all for the help!
>
> LMH, Yes I would like to see the alternative. I am using this for a
> large data set and if the
Hello,
If speed is important, and following the previous discussion and Bert's
tests, here are two other alternatives, both faster.
1. Bert2 is Bert's original but with scan(., sep = "_") substituted for
unlist/strsplit.
2. A package data.table solution. These are always fast, many times the
That was still slower and doesn't quite give what was requested:
> cbind(F1,utils::strcapture("([^_]*)_(.*)", F1$text,
proto=data.frame(Before_=character(), After_=character(
ID1 ID2 text Before_ After_
1 A1 B1 NONE
2 A1 B1 cf_12 cf 12
3 A1 B1 NONE
4 A2 B2
Another way to make columns out of the stuff before and after the
underscore, with NAs if there is no underscore, is
utils::strcapture("([^_]*)_(.*)", F1$text,
proto=data.frame(Before_=character(), After_=character()))
-Bill
On Tue, Sep 22, 2020 at 4:25 PM Bert Gunter wrote:
> To be clear, I
Oh, if efficiency is a consideration, then my code is about 15 times as
fast as Rui's:
> F2 <- F1[rep(1:5,1e6),] ## 5 million rows
##Rui's
> system.time({
+ F2$Y1 <- +grepl("_", F2$text)
+ tmp <- strsplit(as.character(F2$text), "_")
+ tmp <- lapply(tmp, function(x) if(length(x) == 1)
Thank you all for the help!
LMH, Yes I would like to see the alternative. I am using this for a
large data set and if the alternative is more efficient than this
then I would be happy.
On Tue, Sep 22, 2020 at 6:25 PM Bert Gunter wrote:
>
> To be clear, I think Rui's solution is perfectly fine
To be clear, I think Rui's solution is perfectly fine and probably better
than what I offer below. But just for fun, I wanted to do it without the
lapply(). Here is one way. I think my comments suffice to explain.
> ## which are the non "_" indices?
> wh <- grep("_",F1$text, fixed = TRUE,
Sometimes it just makes more sense to pre-process your data and get it into the
format you need. It
just depends on whether you are more comfortable programing in R or in some
other text manipulation
language like bash/sed/awk/grep etc.
If you know how to do this with other tools, you could
Hello,
A base R solution with strsplit, like in your code.
F1$Y1 <- +grepl("_", F1$text)
tmp <- strsplit(as.character(F1$text), "_")
tmp <- lapply(tmp, function(x) if(length(x) == 1) c(x, ".") else x)
tmp <- do.call(rbind, tmp)
colnames(tmp) <- c("X1", "X2")
F1 <- cbind(F1[-3], tmp)#
Hello,
Something like this?
F1$Y1 <- +grepl("_", F1$text)
F1 <- F1[c(1, 2, 4, 3)]
F1 <- tidyr::separate(F1, text, into = c("X1", "X2"), sep = "_", fill =
"right")
F1
Hope this helps,
Rui Barradas
Às 19:55 de 22/09/20, Val escreveu:
HI All,
I am trying to create new columns based on
HI All,
I am trying to create new columns based on another column string
content. First I want to identify rows that contain a particular
string. If it contains, I want to split the string and create two
variables.
Here is my sample of data.
F1<-read.table(text="ID1 ID2 text
A1 B1 NONE
A1
Dear Burt, you gave a very elegant solution. Many thanks!
Jeff, I understand your solution, thank you very much for your time!
Colleague Milos, patronage is exactly what I need. I hope for your
further guidance! (Rcmdr is not enough for some purposes.)
Dear Ivan, I used your solution! It's the
J have just seen your follow-up post (out of tread). I don’t want to be
rude or patronizing but few caveats.
Neither R nor R help are meant to be user friendly. Learning curve is steep
but very rewarding at the end.
Problem you have can be solved in a literary hundred ways. Unfortunately,
your
Do you mean IQR? -- I don't know what ICR means.
If so, see IQR.
More generally see ?by or more generally ?tapply to obtain whatever sort of
summary you want.
e.g.
> d <-data.frame( x = runif(10), w = rep(c("a","b"),5))
> by(d$x, d$w, FUN = function(x)c(median = median(x),IQR = IQR(x)))
d$w: a
If I understand correctly you need summary by group. I would suggest
arsenal package and tableby
tab1 <- tableby(group ~ anova(var, "meansd", digits=1) + #mean and sd +
round to 1 digit + anova
kwt(var, "medianq1q3", digits=1) , #median q1 and q3 +
round to 1 digit +
On Mon, 23 Dec 2019 17:56:35 +0300
Medic wrote:
> I would like to split
> mydata$var
> by
> mydata$group #to get var1 and var2
There is the split() function that does exactly that (except it returns
a list instead of multiple variables)...
> And then get
> summary (var1, var2) #this is my
I have
mydata$var
#this is ONE group of patients
And I would like to get
median and ICR of mydata$var.
How can I get this?
With summary (mydata$var)!
Ok!
And now I would like to get THE SAME, but for TWO group: male and
female (which are contained in the group mydata$var)
How can I get this?
Not clear what you mean by
summary (var1, var2)
? That is not a legal way to call summary. Perhaps
mt <- mtcars[,c("cyl","hp")]
mt$cyl <- factor( mt$cyl )
mtl <- split(mt[,"hp",drop=FALSE], mt$cyl)
lapply(mtl,summary)
On December 23, 2019 6:56:35 AM PST, Medic wrote:
>I have
>mydata$var
>
?ave
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Dec 23, 2019 at 6:57 AM Medic wrote:
> I have
> mydata$var
>
> and I have
> mydata$group #two group
I have
mydata$var
and I have
mydata$group #two group
I would like to split
mydata$var
by
mydata$group #to get var1 and var2
And then get
summary (var1, var2) #this is my finite aim
How to encode it all?
__
R-help@r-project.org mailing list -- To
Thank you Jeff and Rainer. I will try Jeff's idea using the sub
string. function to extract the year and split on that.
Thanks again to both--EK
On Sat, Mar 16, 2019 at 1:52 AM Jeff Newmiller wrote:
>
> Couldn't you just use the substr function to pull the year out yourself to
> make the
In your sample data.frame, MyDate and MyDes are factors; is that what you want?
rs
On Samstag, 16. März 2019 01:40:01 CET Ek Esawi wrote:
> Hi All—
>
> I have a data frame with over 13000 rows and 4 columns. A mini data
> frame is given at the bottom. I want to split the data frame into
> lists
Couldn't you just use the substr function to pull the year out yourself to make
the grouping column?
On March 15, 2019 10:40:01 PM PDT, Ek Esawi wrote:
>Hi All—
>
>I have a data frame with over 13000 rows and 4 columns. A mini data
>frame is given at the bottom. I want to split the data frame
Hi All—
I have a data frame with over 13000 rows and 4 columns. A mini data
frame is given at the bottom. I want to split the data frame into
lists each corresponds to single year which ranges from 1990 to 2018).
I wanted to use the split function, but it requires a vector of the
same length as
Hi!
How about this:
--- snip --
for (i in 1:(length(split_str)-1)) {
assign(paste("DF",i,sep=""),DF[
c((which(DF$name==split_str[i])+1):(which(DF$name==split_str[i+1])-1)),
])
}
--- snip ---
'assign' creates for each subset a new data.frame DFn, where n ist a
count (1,2,...).
But note:
Forgot to take care of the boundary conditions:
# revised data.frame to take care of boundary conditions
DF = data.frame(name = c('b', 'a','v','z', 'c','d'), val = 0); DF
## name val
## 1b 0
## 2a 0
## 3v 0
## 4z 0
## 5c 0
## 6d 0
split_str = c('a', 'c')
#
...
yes, but note that:
which(data[[col]] %in% s
can be replaced directly by match:
match(data[[col]], s)
Corner cases (nothing matches, etc.) would also have to be checked and
probably should sort the matched row numbers for safety.
Cheers,
Bert
Bert Gunter
"The trouble with having an open
DF = data.frame(name = c('a', 'v', 'c'), val = 0); DF
## name val
## 1a 0
## 2v 0
## 3c 0
split_str = c('a', 'c')
# If we assume that the values in split_str are ordered in the same order
as in the dataframe, then this might work.
offsets <- match(split_str, DF$name)
# Since
Hello,
Maybe something like the following.
splitDF <- function(data, col, s){
n <- nrow(data)
inx <- which(data[[col]] %in% s)
lapply(seq_along(inx), function(i){
k <- if(inx[i] < n) (inx[i] + 1):(inx[i + 1])
data[k, ]
})
}
splitDF(DF, "name", split_str)
Hope
Hi,
I am struggling to split a data.frame as will below scheme :
DF = data.frame(name = c('a', 'v', 'c'), val = 0); DF
split_str = c('a', 'c')
Now, for each element in split_str, R should find which row of DF contains
that element, and return DF with all rows starting from next row of the
Hi Charlie and Bert,
Thank you both for the suggestions and pointers. I will look into them.
FYI I repeatedly refer to tidyquant because that package refers to itself as
"tidyquant: Tidy Quantitative Financial Analysis" and I am hoping to get the
attention of someone who is involved in the
Thanks for the reminder about lattice! I did some searching and there's
a good example of manipulating the size of subplots using the `position`
argument (see pp. 202-203 in the Trellis Users Guide:
http://ml.stat.purdue.edu/stat695t/writings/Trellis.User.pdf). This is
not within the paneling
That (the need for base graphics) is false. It certainly **can** be done in
base graphics -- see ?layout for a perhaps more straightforward way to do
it along the lines you suggest.
However both lattice and ggplot are based on grid graphics, which has a
similar but slightly more flexible
For this kind of control you will probably need to move to base graphics
and utilize the `fig` argument in par(), in which case you would want to
run the plot() command twice: once with your first outcome and once with
your second, changing the par() settings before each one to control the
Hi Charlie,
Thanks. This is helpful. As mentioned in my original question, I want to be
able to plot a few such charts on the same page,
say a 2 x 2 grid with such a chart for each of 4 different stocks. Using
your solution I accomplished this by making
a list pLst of your ggplots and then calling
So the general strategy for getting these into separate panels in ggplot
is to have a single variable that will be your response and a factor
variable that indexes which original variable it came from. This can be
accomplished in many ways, but the way I use is with the melt() function
in the
If you don't want to wait for a ggplot2 solution, here are two
alternatives you can use right now:
chartSeries(SPYxts)
# or (with xts > 0.10
plot(SPYxts$SPY.Close)
addSeries(SPYxts$SPY.Volume, type = "h")
You might also try autoplot.zoo(), though I've never used it.
On Thu, Jan 18, 2018 at
Hi Charlie,
I am comfortable to put the data in any way that works best. Here are two
possibilities: an xts and a data frame.
library(quantmod)
quantmod::getSymbols("SPY") # creates xts variable SPY
SPYxts <- SPY[,c("SPY.Close","SPY.Volume")]
SPYdf <-
Could you provide some information on your data structure (e.g., are the
two time series in separate columns in the data)? The solution is fairly
straightforward once you have the data in the right structure. And I do
not think tidyquant is necessary for what you want.
Best,
Charlie
--
A very common chart in the financial markets is a split chart with two time
series shown in two vertically stacked sub-charts.
A classic case would be the top panel showing the time series of historical
prices of some stock, and the bottom
panel showing the volume traded per day immediately below
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
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:
>
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
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.
>
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:
> 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
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
fox
From: R-help [r-help-boun...@r-project.org] on behalf of Massimo Bressan
[massimo.bres...@arpa.veneto.it]
Sent: March 27, 2016 5:45 PM
To: r-help@r-project.org
Subject: [R] 'split-lapply' vs. 'aggregate'
this might be a trivial question (eventually sorry for that!) but I definit
this might be a trivial question (eventually sorry for that!) but I definitely
can not catch the problem here...
please consider the following reproducible example: why of different results
through 'split-lapply' vs. 'aggregate'?
I've been also through a check against different methods (e.g.
or strsplit?
test <-"k0298_7832_8964"
# Split and remove letters
test <- unlist(strsplit(test, "\\_"))
test <- gsub("[a-z]", "", test[1])
# Split on letters and underscore
test <-"k0298_7832_8964"
test <- unlist(strsplit(test, "[a-z]|\\_"))
test[2]
On Thu, 18 Feb 2016 at 18:43 Ben Tupper
Hi,
Will substring work for you?
?substring
Cheers,
Ben
> On Feb 18, 2016, at 12:36 PM, Marine Regis wrote:
>
> Hello,
>
>> From this character string:
>
> test <-"k0298_7832_8964"
>
> how can I obtain:
>
> [[1]]
>
> "0298"
>
> Thank you very much for your
Hello,
>From this character string:
test <-"k0298_7832_8964"
how can I obtain:
[[1]]
"0298"
Thank you very much for your help.
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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",
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
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
> 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:
Hello,
I wonder if you might be able to help me. I'm enrolled in an R programming
course through Coursera. I've done well so far--though it's been
challenging!--but I'm having trouble understanding exactly how "split" and
the loop functions (like "lapply") work.
I keep getting an error that
You should really be asking Coursera for help with its course.
However you can figure this out by breaking down your commands
into small steps and seeing what each step gives. This is an advantage
of an interactive system like R. E.g., suppose you start with
> s1 <- data.frame(state=c("Rhode
On Jun 10, 2015, at 12:18 PM, David Winsemius wrote:
On Jun 10, 2015, at 5:39 AM, Liz Hare wrote:
Hi R-Experts,
I have a data.frame like this:
head(map)
chr snp poscm posbpdist
1 1 M1 2.99043 3249189 NA
2 1 M2 3.06457 3273096 0.07414
3 1 M3 3.17018 3307151
On Jun 10, 2015, at 2:21 PM, Marc Schwartz marc_schwa...@me.com wrote:
On Jun 10, 2015, at 7:39 AM, Liz Hare dogg...@earthlink.net wrote:
Hi R-Experts,
I have a data.frame like this:
head(map)
chr snp poscm posbpdist
1 1 M1 2.99043 3249189 NA
2 1 M2 3.06457
On Jun 10, 2015, at 5:39 AM, Liz Hare wrote:
Hi R-Experts,
I have a data.frame like this:
head(map)
chr snp poscm posbpdist
1 1 M1 2.99043 3249189 NA
2 1 M2 3.06457 3273096 0.07414
3 1 M3 3.17018 3307151 0.10561
4 1 M4 3.20892 3319643 0.03874
5 1 M5
On Jun 10, 2015, at 7:39 AM, Liz Hare dogg...@earthlink.net wrote:
Hi R-Experts,
I have a data.frame like this:
head(map)
chr snp poscm posbpdist
1 1 M1 2.99043 3249189 NA
2 1 M2 3.06457 3273096 0.07414
3 1 M3 3.17018 3307151 0.10561
4 1 M4 3.20892 3319643
Hi R-Experts,
I have a data.frame like this:
head(map)
chr snp poscm posbpdist
1 1 M1 2.99043 3249189 NA
2 1 M2 3.06457 3273096 0.07414
3 1 M3 3.17018 3307151 0.10561
4 1 M4 3.20892 3319643 0.03874
5 1 M5 3.28120 3342947 0.07228
6 1 M6 3.29624 3347798 0.01504
I
Thank you very much for the line. It was doing the split as suggested.
However, i want to release all the dataframes to the environment (later
on, for each dataframe, some dozen lines of code will be carried out,
and i dont know how to do it w lapply or for-looping, so i do it
separately):
Did you try dplyr package?
Sergio
Il 23/feb/2015 13:05 Tim Richter-Heitmann trich...@uni-bremen.de ha
scritto:
Thank you very much for the line. It was doing the split as suggested.
However, i want to release all the dataframes to the environment (later
on, for each dataframe, some dozen lines
On Feb 23, 2015, at 4:03 AM, Tim Richter-Heitmann wrote:
Thank you very much for the line. It was doing the split as suggested.
However, i want to release all the dataframes to the environment (later on,
for each dataframe, some dozen lines of code will be carried out, and i dont
know how
1 - 100 of 423 matches
Mail list logo