Thanks, Peter. Why not cbind your idea for the first column with my idea
for the second column and get it done in one line?:
v <- c(1,2,5,6,7,8,25,30,31,32,33)
M <- cbind( v[ c(1, which( diff(v) !=1 ) + 1 ) ] , rle( v - 1:length(v)
)$lengths )
M
[,1] [,2]
[1,]12
[2,]54
[3
f <- function (x) {
isState <- is.element(tolower(x), tolower(state.name))
w <- which(isState)
data.frame(State = x[rep(w, diff(c(w, length(x) + 1)) - 1L)],
City = x[!isState])
}
E.g.,
V1 <-c("alabama", "bates", "tuscaloosa", "smith", "arkansas", "fayette",
"little rock", "alas
Here is a solution using data.table
> require(data.table)
> x <- data.table(v, diff = cumsum(c(1, diff(v)) != 1))
> x
v diff
1: 10
2: 20
3: 51
4: 61
5: 71
6: 81
7: 252
8: 303
9: 313
10: 323
11: 333
> x[, list(value = v[1L], length = .
Here is another approach:
> v <- c(1,2,5,6,7,8,25,30,31,32,33)
>
> # split by differences != 1
> t(sapply(split(v, cumsum(c(1, diff(v)) != 1)), function(x){
+ c(value = x[1L], length = length(x)) # output first value and length
+ }))
value length
0 1 2
1 5 4
225 1
Tena koe Mike
An alternative, which is slightly fast:
diffv <- diff(v)
starts <- c(1, which(diffv!=1)+1)
cbind(v[starts], c(diff(starts), length(v)-starts[length(starts)]+1))
Peter Alspach
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Mike Mill
I have a vector of sorted positive integer values (e.g., postive integers
after applying sort() and unique()). For example, this:
c(1,2,5,6,7,8,25,30,31,32,33)
I want to make a matrix from that vector that has two columns: (1) the
first value in every run of consecutive integer values, and (2
dimnik wrote
> thank you for your answer.Yes,that sounds right.I thought the same thing
> but the problem is how can i generalize the command for every vector of
> numbers not only for the specific example?not only for c(1,2),c(0.1,0.8).
>
> 2015-01-04 0:45 GMT+00:00 Pete Brecknock [via R] <
> ml
On Sun, 4 Jan 2015, Duncan Murdoch wrote:
On 04/01/2015 5:13 PM, Mike Miller wrote:
The help doc for readBin writeBin tells me this:
Handling R's missing and special (Inf, -Inf and NaN) values is discussed
in the ‘R Data Import/Export’ manual.
So I go here:
http://cran.r-project.org/doc/manu
On 04/01/2015 5:13 PM, Mike Miller wrote:
> The help doc for readBin writeBin tells me this:
>
> Handling R's missing and special (Inf, -Inf and NaN) values is discussed
> in the ‘R Data Import/Export’ manual.
>
> So I go here:
>
> http://cran.r-project.org/doc/manuals/r-release/R-data.html#Spe
The help doc for readBin writeBin tells me this:
Handling R's missing and special (Inf, -Inf and NaN) values is discussed
in the ‘R Data Import/Export’ manual.
So I go here:
http://cran.r-project.org/doc/manuals/r-release/R-data.html#Special-values
Unfortunately, I don't really understand th
This seems to me to be a case where thinking in terms of computer
programming concepts is getting in the way a bit. Approach it as a data
analysis task; the S language (upon which R is based) is designed in part
for data analysis so there is a function that does most of the job for you.
(I changed
Thanks! So it looks like I can say "R writeBin/readBin does not support
half-precision floats" even though the error message "size 2 is unknown on
this machine" seems to contradict that (for some machine). I tried to
figure out from the source code (src/main/connections.c) how it decides
what
On 04/01/2015 12:12, Duncan Murdoch wrote:
On 04/01/2015 12:31 AM, Mike Miller wrote:
It's an IEEE standard format:
http://en.wikipedia.org/wiki/Half-precision_floating-point_format#IEEE_754_half-precision_binary_floating-point_format:_binary16
This is what I see:
writeBin(vec , con, size=2
Lukas,
Lukas Kohl gmail.com> writes:
>
> Hello R-list
>
> Maybe someone knows what's going on here.
>
> I'm trying to re-run a script I wrote earlier this year using the function
> rda() in the vegan package. The script run fine back then, and I did not
> change the dataset, so I was wanderi
Sorry about the dead lead on the package... it is hexView. It does not support
FP16 directly though... You would have to find another way to make that
conversion. Some people have posted code that may be usable with Rcpp [1]. I
believe your architecture may support hardware conversion of FP32 t
thank you for your answer.Yes,that sounds right.I thought the same thing
but the problem is how can i generalize the command for every vector of
numbers not only for the specific example?not only for c(1,2),c(0.1,0.8).
2015-01-04 0:45 GMT+00:00 Pete Brecknock [via R] <
ml-node+s789695n4701358...@n
Dear Monnad,
one possible way would be to use as.factor() and in the summary you would get
counts for every level.
Like this:
x = c("1", "1", "2", "1", "5", "2")
summary(as.factor(x))
Cheers, Christian
> Hi all,
>
> I thought this was a very naive problem but I have not found any solution
I'm coming to R from Python, so I coded a Python3 solution:
#
data = """alabama
bates
tuscaloosa
smith
arkansas
fayette
little rock
alaska
juneau
nome
""".split()
state_list = ["alabama", "arkansas", "alaska"] # etc.
return_list = []
for word in data:
if word in state_l
On 04/01/2015 12:31 AM, Mike Miller wrote:
> It's an IEEE standard format:
>
> http://en.wikipedia.org/wiki/Half-precision_floating-point_format#IEEE_754_half-precision_binary_floating-point_format:_binary16
>
> This is what I see:
>
>> writeBin(vec , con, size=2 )
> Error in writeBin(vec, con,
Following the posting guide and hence reading the help page first helps:
"Possible sizes are 1, 2, 4 and possibly 8 for integer or logical
vectors, and 4, 8 and possibly 12/16 for numeric vectors."
Best,
Uwe Ligges
On 04.01.2015 08:03, Mike Miller wrote:
Thanks for the pedantic insult, but
> On 04-01-2015, at 10:02, Monnand wrote:
>
> Hi all,
>
> I thought this was a very naive problem but I have not found any solution
> which is idiomatic to R.
>
> The problem is like this:
>
> Assuming we have vector of strings:
> x = c("1", "1", "2", "1", "5", "2")
>
> We want to count numb
Hi all,
I thought this was a very naive problem but I have not found any solution
which is idiomatic to R.
The problem is like this:
Assuming we have vector of strings:
x = c("1", "1", "2", "1", "5", "2")
We want to count number of appearance of each string. i.e. in vector x,
string "1" appear
22 matches
Mail list logo