Re: [R] splitting a vector of strings

2016-07-21 Thread Michael Dewey
Dear Eric I think you are looking for sub or gsub Without an example set of input and output I am not quite sure but you would need to define an expression which matches your separator (;) followed by any characters up to the end of line. If you have trouble with that then someone here will n

Re: [R] splitting a vector of strings

2016-07-21 Thread Ben Tupper
Hi, I'm not sure about the more generalized solution, but how about this for a start. x <- c("a;b;c", "d;e", "foo;g;h;i") x #[1] "a;b;c" "d;e" "foo;g;h;i" sapply(strsplit(x, ";",fixed = TRUE), '[',1) #[1] "a" "d" "foo" If you want elegance then I suggest you take a look at the s

[R] splitting a vector of strings

2016-07-21 Thread Eric Elguero
Hi everybody, I have a vector of character strings. Each string has the same pattern and I want to split them in pieces and get a vector made of the first pieces of each string. The problem is that strsplit returns a list. All I found is uu<- matrix(unlist(strsplit(x,";")),ncol=3,byrow=T)[,1]

Re: [R] Splitting a vector into data frame

2016-03-24 Thread Ivan Calandra
Hi! As Boris explained, if you do not always have the same number of values per country, you need to provide more details, e.g. should the empty cells be filled with NA? But if you do always have 20 values per country (unlike in your sample data), then this could work for you: mydf <- data.

Re: [R] Splitting a vector into data frame

2016-03-24 Thread Jim Lemon
Hi Burhan, As all of your values seem to be character, perhaps: country.df<-as.data.frame(matrix(temp.data,ncol=22,byrow=TRUE)[,2:21]) if there really are 2 country names and 20 values for each country. As Boris has pointed out, there are different numbers of values following the country names in

Re: [R] Splitting a vector into data frame

2016-03-24 Thread Boris Steipe
Your data rows have different numbers of columns. Thus your problem is not sufficiently specified. B. On Mar 24, 2016, at 6:30 AM, Burhan ul haq wrote: > Hi, > > 1. I have scraped some data from the web, subset shown below > >> dput(temp.data) > c("Armenia", "Armenia", "43827", "39200", "357

[R] Splitting a vector into data frame

2016-03-24 Thread Burhan ul haq
Hi, 1. I have scraped some data from the web, subset shown below > dput(temp.data) c("Armenia", "Armenia", "43827", "39200", "35700", "36700", "39341", "30571", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", " 0", "0", "0", "0", "0", "Austria", "Austria", "135417", "166200", "144500", "147300"

Re: [R] Splitting a vector

2013-12-11 Thread Gerrit Eichner
Hello, Long Vo, take a look at the help page of split or directly at str(Y) They tell you that Y is a list, and list components are indexed using "[[": mean(Y[[4]]) should do what you want. Regards -- Gerrit This does what I needed. However, as the output is a list object, is there

Re: [R] Splitting a vector

2013-12-10 Thread Long Vo
This does what I needed. However, as the output is a list object, is there any way to apply a function to such object? For example if I want to compute the mean for the 4th subvectors, I can't simply use: # Y=split(X,as.numeric(gl(length(X),3,length(X mean(Y[4]) # as the error message

Re: [R] Splitting a vector

2013-12-10 Thread Jeff Newmiller
You don't need to wrap 1:12 in c(). Since matrices are just folded vectors, you can convert vector X to a matrix Xm: Xm <- matrix( X, nrow=3 ) and access columns to get your your sub-vectors: Xm[,1] Xm[,2] and so on. --

Re: [R] Splitting a vector

2013-12-09 Thread arun
Hi, Try: split(X,as.numeric(gl(length(X),3,length(X A.K. Hi, I am quite new to R so I know that this probably is very basic , but how can I split a sequence of number into multiple parts with equal length? For example I have a vector X=c(1:12) I simply need to split it into sub-vectors

[R] Splitting a vector

2013-12-09 Thread Long Vo
Hi, I am quite new to R so I know that this probably is very basic , but how can I split a sequence of number into multiple parts with equal length? For example I have a vector X=c(1:12) I simply need to split it into sub-vectors with the same length N . Say N=3 then I need the output to be like

Re: [R] splitting a vector

2012-08-02 Thread Jan van der Laan
I come up with: runs <- function(numbers) { tmp <- diff(c(0, which(diff(numbers) <= 0), length(numbers))) split(numbers, rep(seq_along(tmp), tmp)) } Can't say it's elegant, but it seems to work runs(c(1:3, 1:4)) $`1` [1] 1 2 3 $`2` [1] 1 2 3 4 runs(c(1,1,1)) $`1` [1] 1 $`2` [1]

Re: [R] splitting a vector

2012-08-01 Thread William Dunlap
, August 01, 2012 6:30 AM > To: r-help@r-project.org > Subject: [R] splitting a vector > > Hello, > > I have a vector with positive integer numbers, e.g. > > > numbers <- c(1,2,1,2,3,4,5) > > and want to split the vector whenever an element in the vector is smaller or

Re: [R] splitting a vector

2012-08-01 Thread Rui Barradas
Hello, Try the following. fun <- function(x){ n.diff <- cumsum(diff(c(x[1], x)) <= 0) split(x, n.diff) } numbers <- c(1,2,1,2,3,4,5) fun(numbers) fun( c(1,1,2,3,4,5,1,2,3,2,3,4,5,6,4,5) ) Hope this helps, Rui Barradas Em 01-08-2012 14:29, capy_bara escreveu: Hello, I have a vecto

[R] splitting a vector

2012-08-01 Thread capy_bara
Hello, I have a vector with positive integer numbers, e.g. > numbers <- c(1,2,1,2,3,4,5) and want to split the vector whenever an element in the vector is smaller or equal to its predecessor. Hence I want to obtain two vectors: c(1,2) and c(1,2,3,4,5). I tried with which(), but it is not so el

Re: [R] Splitting a Vector

2011-01-06 Thread Greg Snow
January 06, 2011 6:09 AM > To: r-help > Subject: [R] Splitting a Vector > > Hi all, > > I read in a text book, that you can examine a variable that is colinear > with others, and giving different ANOVA output and explanatory power > when ordered differently in the model f

[R] Splitting a Vector

2011-01-06 Thread Ben Ward
Hi all, I read in a text book, that you can examine a variable that is colinear with others, and giving different ANOVA output and explanatory power when ordered differently in the model forula, by modelling that explanatory variable, against the others colinear with it. Then, using that info

Re: [R] splitting a vector of strings...

2009-10-22 Thread andrew
eem > to be working.  Thanks! > > --j > > > > William Dunlap wrote: > >> -Original Message- > >> From: r-help-boun...@r-project.org > >> [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Greenberg > >> Sent: Thursday, October

Re: [R] splitting a vector of strings...

2009-10-22 Thread Jonathan Greenberg
s! --j William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Greenberg Sent: Thursday, October 22, 2009 7:35 PM To: r-help Subject: [R] splitting a vector of strings... Quick question -- if I have a vector of s

Re: [R] splitting a vector of strings...

2009-10-22 Thread andrew
xs <- "this is string" xsv <- paste(xs, 1:10) sapply(xsv, function(x) strsplit(x, '\\sis\\s')) This will split the vector of string "xsv" on the word 'is' that has a space immediately before and after it. On Oct 23, 1:34 pm, Jonathan Greenberg wrote: > Quick question -- if I have a vector of s

Re: [R] splitting a vector of strings...

2009-10-22 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Greenberg > Sent: Thursday, October 22, 2009 7:35 PM > To: r-help > Subject: [R] splitting a vector of strings... > > Quick question -- if I

[R] splitting a vector of strings...

2009-10-22 Thread Jonathan Greenberg
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

Re: [R] Splitting a vector into equal groups

2009-05-05 Thread Uwe Ligges
utkarshsinghal wrote: Hi All, I have vector of length 52, say, x=sample(30,52,replace=T). I want to sort x and split into five *nearly equal groups*. Note that the observations are repeated in x so in case of a tie I want both the observations to fall in same group. This seems a very common

Re: [R] Splitting a vector into equal groups

2009-05-04 Thread Berwin A Turlach
G'day Utkarsh, On Mon, 04 May 2009 11:51:21 +0530 utkarshsinghal wrote: > I have vector of length 52, say, x=sample(30,52,replace=T). I want to > sort x and split into five *nearly equal groups*. What do you mean by *nearly equal groups*? The size of the groups should be nearly equal? The sum

Re: [R] Splitting a vector into equal groups

2009-05-04 Thread Dimitris Rizopoulos
check functions cut() and quantile(), and cut2() from package Hmisc; maybe the following is close to what you want: x <- sample(30, 52, replace = TRUE) k <- 5 # how many groups qs <- quantile(x, seq(0, 1, length.out = k + 1)) y <- cut(x, round(qs), include.lowest = TRUE) y table(y) I hope it

Re: [R] Splitting a vector into equal groups

2009-05-04 Thread ronggui
lattice:::equal.count may be what you want. 2009/5/4 utkarshsinghal : > Hi All, > > I have vector of length 52, say, x=sample(30,52,replace=T). I want to > sort x and split into five *nearly equal groups*. Note that the > observations are repeated in x so in case of a tie I want both the > observa

[R] Splitting a vector into equal groups

2009-05-03 Thread utkarshsinghal
Hi All, I have vector of length 52, say, x=sample(30,52,replace=T). I want to sort x and split into five *nearly equal groups*. Note that the observations are repeated in x so in case of a tie I want both the observations to fall in same group. This seems a very common task to do, but still I c

Re: [R] splitting a vector on comma

2008-05-05 Thread Henrique Dallazuanna
Try: scan(textConnection(u), sep=",") On Mon, May 5, 2008 at 12:59 AM, Georg Ehret <[EMAIL PROTECTED]> wrote: > Dear R Usergroup, > I have the following vector and I would like to split it on ",". > How can I do this? > > u > [1] > > "160798191,160802762,160813395,160816017,160817873,160

Re: [R] splitting a vector on comma

2008-05-04 Thread David Scott
?strsplit On Sun, 4 May 2008, Georg Ehret wrote: Dear R Usergroup, I have the following vector and I would like to split it on ",". How can I do this? u [1] "160798191,160802762,160813395,160816017,160817873,160824082,160825247,160826925,160834272,160836257," Thank you in advance!

[R] splitting a vector on comma

2008-05-04 Thread Georg Ehret
Dear R Usergroup, I have the following vector and I would like to split it on ",". How can I do this? > u [1] "160798191,160802762,160813395,160816017,160817873,160824082,160825247,160826925,160834272,160836257," Thank you in advance! With my best regards, Georg. *