Displaying 20 results from an estimated 1000 matches similar to: "dplyr - add/expand rows"
2017 Nov 27
2
dplyr - add/expand rows
try this:
##########################################
library(dplyr)
input <- tribble(
~station, ~from, ~to, ~record,
"07EA001" , 1960 , 1960 , "QMS",
"07EA001" , 1961 , 1970 , "QMC",
"07EA001" , 1971 , 1971 , "QMM",
"07EA001" , 1972 , 1976 , "QMC",
"07EA001" , 1977 ,
2017 Nov 26
0
dplyr - add/expand rows
To David W.'s point about lack of a suitable reprex ("reproducible
example"), Bill's solution seems to be for only one station.
Here is a reprex and modification that I think does what was requested for
multiple stations, again using base R and data frames, not dplyr and
tibbles.
First the reprex with **two** stations:
> d <- data.frame( station =
2017 Nov 28
0
dplyr - add/expand rows
On 11/26/2017 08:42 PM, jim holtman wrote:
> try this:
>
> ##########################################
>
> library(dplyr)
>
> input <- tribble(
> ~station, ~from, ~to, ~record,
> "07EA001" , 1960 , 1960 , "QMS",
> "07EA001" , 1961 , 1970 , "QMC",
> "07EA001" , 1971 , 1971 ,
2017 Nov 28
2
dplyr - add/expand rows
Or with the Bioconductor IRanges package:
df <- with(input, DataFrame(station, year=IRanges(from, to), record))
expand(df, "year")
DataFrame with 24 rows and 3 columns
station year record
<character> <integer> <character>
1 07EA001 1960 QMS
2 07EA001 1961 QMC
3 07EA001 1962 QMC
4
2017 Nov 29
2
dplyr - add/expand rows
On 11/29/2017 04:15 PM, T?th D?nes wrote:
> Hi,
>
> A benchmarking study with an additional (data.table-based) solution.
I don't think speed is the right benchmark (I do agree that correctness
is!).
For the R-help list, maybe something about least specialized R knowledge
required would be appropriate? I'd say there were some 'hard' solutions
-- Michael (deep
2017 Nov 29
0
dplyr - add/expand rows
Hi,
A benchmarking study with an additional (data.table-based) solution.
Enjoy! ;)
Cheers,
Denes
--------------------------
## packages ##########################
library(dplyr)
library(data.table)
library(IRanges)
library(microbenchmark)
## prepare example dataset ###########
## use Bert's example, with 2000 stations instead of 2
d_df <- data.frame( station =
2017 Nov 28
1
dplyr - add/expand rows
Bert wrote
... Bill's solution seems to be for only one station.
No, it works for any number of stations.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Sun, Nov 26, 2017 at 11:10 AM, Bert Gunter <bgunter.4567 at gmail.com>
wrote:
> To David W.'s point about lack of a suitable reprex ("reproducible
> example"), Bill's solution seems to be for only one
2017 Nov 29
0
dplyr - add/expand rows
Hi Martin,
On 11/29/2017 10:46 PM, Martin Morgan wrote:
> On 11/29/2017 04:15 PM, T?th D?nes wrote:
>> Hi,
>>
>> A benchmarking study with an additional (data.table-based) solution.
>
> I don't think speed is the right benchmark (I do agree that correctness
> is!).
Well, agree, and sorry for the wording. It was really just an exercise
and not a full
2017 Nov 26
0
dplyr - add/expand rows
> On Nov 25, 2017, at 11:18 AM, Hutchinson, David (EC) <david.hutchinson at canada.ca> wrote:
>
> I have a returned tibble of station operational record similar to the following:
>
>> data.collection
> # A tibble: 5 x 4
> STATION_NUMBER YEAR_FROM YEAR_TO RECORD
> <chr> <int> <int> <chr>
> 1 07EA001 1960
2017 Nov 25
0
dplyr - add/expand rows
I have a returned tibble of station operational record similar to the following:
> data.collection
# A tibble: 5 x 4
STATION_NUMBER YEAR_FROM YEAR_TO RECORD
<chr> <int> <int> <chr>
1 07EA001 1960 1960 QMS
2 07EA001 1961 1970 QMC
3 07EA001 1971 1971 QMM
4 07EA001 1972 1976 QMC
5
2018 Jan 19
1
Web scraping different levels of a website
Hey Ilio,
I revisited the previous code i posted to you and fixed some things.
This should let you collect as many studies as you like, controlled by
the num_studies arg.
If you try the below url in your browser you can see that it returns a
"simpler" version of the link you posted. To get to this you need to
hit F12 to open Developer Tools --> go to Network tab and click on the
2001 Apr 30
2
margin problems?
hi, All. I'm using R 1.2.2 on a linux box.
I have very long labels on my y axis, and when I try to print them
out, they always come out clipped so I can't see them. How do I
change the margin for the y axis? I've tried mai and mar, but they
don't seem to do anything...
process.names <- c("Makeprod-data", "Makeprod-QMM", "Search",
2017 Jul 05
4
Help with reshape/reshape2 needed
Hi all:
I'm struggling with getting my data re-formatted using functions in
reshape/reshape2 to get from:
1957 0.862500000
1958 0.750000000
1959 0.300000000
1960 0.287500000
1963 0.675000000
1964 0.937500000
1965 0.025000000
1966 0.387500000
1969 0.087500000
1970 0.275000000
1973 0.500000000
1974 0.362500000
1976 0.925000000
1978 0.712500000
1979 0.337500000
1980 0.700000000
1981 0.425000000
2012 Dec 17
1
subset handling
Dear Rui and UseRs,[a text file has also been attached, in case the format of my email is difficult to get]I am extremely sorry that I am bothering you once again, but I?ll have to get to the bottom of it. The following command
sp <- lapply(split(agg, agg$st), function(x) x[order(x$year, x$month), ])
gave me an output with monthly mean of population(as under). i am not able to apply
2010 Jan 13
8
How to use getCenter
Hi,
I am starting to use Mapstraction with the openlayers provider, and I am not
sure how to retrieve the current center of a map in a cross-provider way.
i.e. currently when calling map.getCenter(), the result returned is the
openlayers internal one, not the long/lat used when calling setCenter().
Is that the expected behaviour?
Regards,
Philippe
-------------- next part --------------
An
2017 Jul 05
0
Help with reshape/reshape2 needed
This does not use reshape/reshape2, but it is pretty straightforward. Assuming X is your example data:
> Y <- split(X[, 2], X[, 1])
> vals <- sapply(Y, length)
> pad <- max(vals) - vals
> Y2 <- lapply(seq_along(Y), function(x) c(Y[[x]], rep(NA, pad[x])))
> names(Y2) <- names(Y)
> X2 <- do.call(cbind, Y2)
> X2[, 1:6]
1957 1958 1959
1998 Aug 26
2
Printing NT to Linux w\Cannon bjc-4000
I am able to see my printer as a share. Well better put, I see four
representations of my printer: ascii, lp2, lp-mono, and raw. I tried
the naive thing and just selected lp2 and added the cannon bjc 4000
driver for NT. This didn't work. I get an error report:
%%[ Error: undefined; offending Command: K ]%% . . . a bunch of strings
that I don't understand. This does not look like the
2010 Jan 11
3
interpolation
Dear R-users,
I have a complex line by xy-values (ordered by z).
And I would like to get interpolated y-values on the positions of x = 0:600.
How do I get the correct points?
x=c(790,790,790,790,790,786,783,778,778,766,763,761,761,761,715,628,521,350,160,134,134,129,108,101,93,111,161,249,288,243,139,45,7)
2008 Nov 04
1
perform Kruskal-Wallis test without using the built-in command in R
Hi,
again i am stuck in my presentation, and i have never learn R before in my
life but need this to be done, so please help me out for a favour:
http://www.nabble.com/file/p20333155/kew.dat kew.dat
run this in R and these comes up:
Month Year Rain
1 Jan 1900 74.400000
2 Feb 1900 80.500000
3 Mar 1900 23.600000
4 Apr 1900 23.600000
5 May 1900 25.100000
6
2017 Jul 05
0
Help with reshape/reshape2 needed
The reason it doesn't work easily with reshape/reshape2 is that the
order of the rows is not determined. Your answer could be
1957 1958 ... 1985 1986
0.8625000 0.7500000 ... 0.7307692 0.23750000
0.0733945 0.6435644 ... NA 0.05769231
0.5096154 NA ... NA 0.65137615
or
1957 1958 ... 1985 1986
0.0733945 0.6435644 ... NA