Questions tagged [dcast]
267 questions
2
votes
3 answers
Reshaping EPA wind speed & direction data with dcast in R
I am trying to convert long format wind data into wide format. Both wind speed and wind direction are listed within the Parameter.Name column. These values need to be cast by both Local.Site.Name, and Date.Local variables.
If there are multiple…

philiporlando
- 941
- 4
- 19
- 31
2
votes
1 answer
dcast and summary into a function - argument lost
I am trying to turn the following code, which works properly, into a function.
result_check <- data %>%
group_by(column, target) %>%
summarise(Unique_Elements = n()) %>%
dcast(column_code ~ target, value.var="Unique_Elements")
For example,…

Prometheus
- 1,977
- 3
- 30
- 57
2
votes
1 answer
Apply dcast() function to the list of dataframes
I have a list of data frames which I show some of it below:
> str(ls.df.val.keep)
List of 87
$ AT_VALUES_IMV_EU28_EXTRA :'data.frame': 1554 obs. of 4 variables:
..$ PARTNER : Factor w/ 3 levels "EU28_EXTRA","EU28_INTRA",..: 1 1 1 1 1 1…

Feraman
- 39
- 6
2
votes
2 answers
How to replicate dcast() from R in SQL Server
Currently I'm using R to transform my table data of the form:
ID Code Condition WT
104 KEENTRAN CON4 .30577
. . . .
. . . .
The link should work for anyone who would like to download my…

Rick Arko
- 680
- 1
- 8
- 27
2
votes
4 answers
Applying dcast in a weird way
I want to seperate variables according to a "lead" variable. x3 in the following case:
set.seed(2)
df = data.frame(x1 = sample(4), x2 = sample(4), x3 = sample(letters[1:2], size = 4, replace = TRUE))
df
# x1 x2 x3
# 1 1 4 a
# 2 3 3 b
# 3 2 …

jakob-r
- 6,824
- 3
- 29
- 47
1
vote
1 answer
Convert table DT1 to DT2 fill with binary using data.table
I have DT1 and try to convert this table to DT2 with 1,0
DT1<-fread("variable bf_target_N bf_comparator_N
drugA 2 1
drugB 3 4
drugC 4 5
")
DT2<-fread("type drugA drugB drugC
bf_target_N 1 1 1
bf_target_N 1 1 …

zell kim
- 69
- 5
1
vote
0 answers
How to build a dataset that, for each time period, matches the individual elements entering the dataset until a condition is reached
I have a problem with a piece of code that was suggested in the post: How to create a data set that, for each hour, matches the individual elements entering the dataset until a condition has been reached in R
I have two different data tables that…

bLanton70
- 17
- 4
1
vote
2 answers
dcasting long table along multiple columns
I am having a difficult time understanding dcast, and cannot get the right commands to get what I want. I will give a minimal repro.
#generate the data
ID <- c('a','a','a','b','b','b')
Parameter <- c('p1','p2','p3','p1','p2','p3')
Value <-…

David Inman
- 95
- 7
1
vote
1 answer
How do I use dcast and keep data from multiple years?
I have a .csv table with world bank development data from the years 2016-2020. In the beginning I only used data from 2020, however I had to add years as for some of the variables the data was not available.
The .csv table contained countrycodes and…

Jana
- 13
- 3
1
vote
4 answers
How can I use dcast based on multiple columns?
I have data on this form in a data.table DT:
DT = data.table(
year=c('1981', '1981', '1981', '2005', '2005', '2005'),
value=c(2, 8, 16, 3, 9, 27),
order…

Hal
- 75
- 6
1
vote
1 answer
How do I transpose observations into variables/columns?
I've got a data frame that looks something like this:
precinct, race, age, people
1001, black, 18-40, 1
1001, white, 18-40, 2
1001, hispanic, 18-40, 3
1001, asian, 18-40, 4
1001, black, 40 or older, 5
1001, white, 40 or older, 6
1001, hispanic, 40…

Generic_User_ID
- 1,067
- 2
- 13
- 16
1
vote
1 answer
What am I doing wrong in this dcast (reshape2) function?
So I have this table
and I need to arrange it by team as rows and year (2010 - 2015) as attributes, so Ive tried
with xtabs and table function, but I only get the count, instead of the points that the table contains.
Tried
dcast(EvoTeam,…

kaezar22
- 11
- 2
1
vote
1 answer
R how to use fun.aggregate to keep only middle values
I have a dataframe of the form:
col1
var
value
A
VAR1
1
B
VAR1
2
C
VAR1
3
A
VAR2
4
B
VAR1
5
A
VAR1
6
A
VAR1
7
I have applied following dcast without fun.aggregate:
dcast(dataframe, col1~var, value.var="value")
Iam getting…

FRECEENA FRANCIS
- 49
- 4
1
vote
2 answers
dcast/spread character-only dataframe with two columns in RHS
I am trying to spread df on two columns in RHS long to wide.
Dataframe I have:
dat <- data.frame(
bm = LETTERS[seq(1,10)],
at4 = c("a1","a2","a3","a4","a5","a6","a7","a8","a9", "a10"),
n1 = c("n1","n2","n3","n4","n5","n6","n7","n8","n9",…

Korpo
- 11
- 2
1
vote
1 answer
How do I repeat the analysis of the frequency/table of categorical variables by group for multiple variables
I created this dataframe Variable_7101 but I would like to repeat this analysis for multiple variables. To be more specific, I have another dataframe (df) with rows containing the other variables that I would like to analyze.
Variable_7101 <-…

Fernanda
- 313
- 1
- 6