All Questions
Tagged with reshape data.table
128
questions
4
votes
2
answers
116
views
How to reference the last column in pivot_longer() without naming it or providing the index number?
I'm writing a function to pivot a data table to long format. For the cols = argument, the name of the first column will always be the same, but the final column (and number of columns) will change. ...
1
vote
1
answer
22
views
How to evaluate the fate (dropped, added or persisted) of species in consecutive years in R
Blockquote
I have several time-series of varying length in a data frame that looks like this:
I want to see if a species dropped or added or persisted from one year to the other year. The output can ...
0
votes
2
answers
102
views
How to reshape data from long to wide format in r?
Now, I have the same input data frame:
AAA <- c('APIS', 'APIS', 'PIPIS', 'AGAROS', 'AGAROS', 'AGAROS', 'NOTHING')
BBB <- c('a', 'a', 'a', 'b', 'b', 'c', NA)
CCC <- c(1, 2, NA, 4, 5, 6, 7)
DDD ...
0
votes
2
answers
52
views
long to wide table on multiple columns in r [duplicate]
I'm having trouble in transform my table from long to wide. Table like :
Con Bro Gr N Freq
Jp CF ii 578 54.3
Jp CF ir 423 45.7
Jp CY im 1835 69.4
Jp CY nm ...
1
vote
4
answers
330
views
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 =c(1,2,3,1,2,3))
year
value
order
'...
3
votes
2
answers
168
views
What is the equivalent of `unstack()` in data.table?
I want to convert the long to wide format of my data using data.table. Normally I use unstack(), but I don't know how to do it in data.table. Below is an example. As output I expect three columns and ...
1
vote
1
answer
343
views
changing a row's place in a R dataframe
i am currently trying to move my 28th row in a dataframe of 30 rows to the 13th row of my dataframe. I have tried the following code, after having seen this post, but I do not fully understand it so ...
5
votes
9
answers
232
views
Wide to long data in R
I have following data in R:
structure(list(Name = 1:4, Paper1 = c("C1", "C1", "C1", "C1"),
Marks1 = 1:4, Paper2 = c("D1", "D1", "D1&...
2
votes
1
answer
304
views
How to stack multiple columns of data.table into a single one?
Let's consider following snippet which has a data.table , and I'm calculating some aggregates, and I've added the sample output as well:
data <- data.table(col=sample(c("col1", "col2&...
0
votes
1
answer
86
views
Reshaping big data long based on column name patterns
I have a (large, in reality) dataset with street blocks; it has house numbers for the beginning ("from", in the variables below) and end ("to") of the block, for both the right and ...
9
votes
5
answers
1k
views
How do I unpack tuple format in R?
Here is the dataset.
library(data.table)
x <- structure(list(id = c("A", "B" ),
segment_stemming = c("[('Brownie', 'Noun'), ('From', 'Josa'), ('Pi', '...
0
votes
3
answers
142
views
How to do a nested 2 level reshape in R?
I am currently working on a survey project that asks about respondents' economic activities. So we will ask the jobs/businesses they have, and since some jobs/businesses are seasonal, we ask about ...
0
votes
2
answers
224
views
Reshape long to wide with two columns to expand in R data.table [R] [duplicate]
I'm trying to convert the following data with two string columns to expand from long to wide. What is the most efficient method in R to achieve the following:
Sample data:
data_sample <- data.frame(...
2
votes
1
answer
625
views
Using melt with data.table only works with multiple measure variables
I'm confused by the behavior of data.table::melt().
I would like to reshape a data.table from wide to long, similar to this question
Here's my data.table:
dt <- data.table(id=c(1,2,3), varA1=c(2,6,...
2
votes
5
answers
306
views
Reshape long data table to list of wide data tables
My question is an expansion of the question posed here
How to reshape data from long to wide format so I will phrase it in a similar way.
The difference is that I want to rearrange one long data table ...