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!
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
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
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]
The following 'f' counts the number of times the sequence x
does not increase. Is this what you want?
> f <- function(x) split(x, cumsum(c(TRUE, x[-1] <= x[-length(x)])))
> f(numbers)
$`1`
[1] 1 2
$`2`
[1] 1 2 3 4 5
> f(c(1,1,2,3,4,5,1,2,3,2,3,4,5,6,4,5))
$`1`
[1] 1
$`2`
[1] 1 2 3 4 5
$`3`
[1
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
I think that you are looking for the 'resid' and 'fitted' functions, these will
give you the residuals and fitted values from an lm object (that added together
gives the original response but are orthogonal to each other). Those values
can then be assigned to a data frame or used by themselves.
the following works - double backslash to remove the "or"
functionality of | in a regex. (Bill Dunlap showed that you don't
need sapply for it to work)
xs <- "this is | string"
xsv <- paste(xs, 1:10)
strsplit(xsv, "\\|")
On Oct 23, 3:50 pm, Jonathan Greenberg wrote:
> William et al:
>
> Th
William et al:
Thanks! I think I have a somewhat more complicated issue due to the
type of string I'm using -- the split is " | " (space pipe space) -- how
do I code that based on your sub code below? Using " | *" doesn't seem
to be working. Thanks!
--j
William Dunlap wrote:
-Ori
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 have a vector of strings tha
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
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!
23 matches
Mail list logo