Questions tagged [dcast]
267 questions
-1
votes
1 answer
dcast() - adding a column that doesnt exist in R
I have encountered a problem, that i am sure has a easy solution, but i cannot find it. I basically summarise my table to get the sum of an value per level of a factor variable:
NOdependants <- unique(claimsMonthly[policyID == policy, .(exposure =…

Nneka
- 1,764
- 2
- 15
- 39
-1
votes
1 answer
Conditionally create a dataframe collapse a collapse a column while truncating actual dataframe
I've a dataframe as under:
+------+----+----------+----------+
| from | to | priority | distance |
+------+----+----------+----------+
| 1 | 3 | 1 | 10 |
| 1 | 5 | 1 | 10 |
| 2 | 7 | 1 | 10 |
| 3…

user11845701
- 157
- 1
- 9
-1
votes
1 answer
Keep tibbles as tibbles after reshape2::dcast
Is there a way to get dcast to output a tibble? (without using as_tibble)
df <- tibble(a = letters[c(rep(1:3, 3), 1)], b = 1:10 + .1, c = 11:20 + .1)
df %>% class
# [1] "tbl_df" "tbl" "data.frame"
df %>% dcast(a ~ b) %>% class
# [1]…

IceCreamToucan
- 28,083
- 2
- 22
- 38
-1
votes
2 answers
R reshape2 or dplyr/tidyr: calculating values' percentage of sub-total
Let's use the airquality dataset as a base.
myaqm <- melt(airquality, id=c("Month", "Day"), na.rm = TRUE)
This gives me a simplification of my real dataset. So far, I've done this:
myaqm_dcast <- dcast(myaqm, Day+variable~Month, value.var =…

Belinda-Jane Netan
- 527
- 6
- 12
-1
votes
1 answer
How to aggregate data.table by applying two functions
I have a data.table that lists the user id, the week number, the fact that a user did something (Processed, either 0 or 1) and a column I just use to count how many values I have, called HowMany:
data <-…

user299791
- 2,021
- 3
- 31
- 57
-2
votes
1 answer
R: how to reshape data frame with the first two columns as independent variable?
I am trying to set up a data frame with month and site as the independent variable, and length as the only dependent variable. But I am not sure which function can help. Currently, I have a long data frame, and I want to make it wide.
I tried to use…

Rhyn
- 135
- 14
-2
votes
1 answer
Undefined columns selected, how to solve?
When I try to run the following code I get an error:
value <- as.matrix(wsu.wide[, c(4, 3, 2)])
Error in [.data.frame(wsu.wide, , c(4, 3, 2)) : undefined columns
selected
How do I get this line of work? It's part of dcasting my data.
This is…

aleksa
- 1
- 2
-2
votes
1 answer
r Using dcast in for loop to find mean of multiple columns and compile them in a new dataframe
I have a dataframe (DF_melted) which I obtained by melting some other dataset. The DF_melted dataframe has columns "month","A","B","C","D","E","F". From the following code using dcast, I am able to get a dataframe which contains value of mean of the…

Sinha
- 431
- 1
- 5
- 12
-3
votes
1 answer
How to reshape data from long to wide format with multiple conditions?
I have a data table called "vsample2.csv" that looks like this:
I need it to look like this in a new data table that I would create:
Tried with dcast but doesn't seem to work. I don't want a function. Just a line or two.
I need to do a repeated…

Venkat Kaushik
- 9
- 5
-3
votes
2 answers
data.table - efficiently manipulate large data set
I am amazed by the blazing speed of data.table. The coding below does exactly what I need however when executed on a large table it does not perform very well.
convinced that this can be done faster with data.table but I do not see how.
Output
The…

Floris Padt
- 796
- 5
- 10
-6
votes
2 answers
How do I transform a data frame where my dates become row entries and not one column of dates?
DF <- structure(list(Date = structure(c(11432, 11797, 11432, 12162,
12528, 13258, 14354, 12162, 12162, 12893, 14719, 14719, 16545,
16545), class = "Date"), Stage = c("Applied", "Screened", "Applied",
"Screened", "Applied", "Screened",…

Jed
- 331
- 2
- 11