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
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
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]
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.
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
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
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"
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
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
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.
--
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
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
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]
, 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
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
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
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
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
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
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
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
> -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
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
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
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
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
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
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
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
?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!
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.
*
31 matches
Mail list logo