Questions tagged [dcast]

267 questions
1
vote
2 answers

Reshaping the dataframe using dcast()

I am trying to reshape my dataframe using dcast() but I am getting this error object 'newid' not found I am not clear about the error. This is the original dataframe Grade Week Subject Location Marks 6 January English …
Nevedha Ayyanar
  • 845
  • 9
  • 27
1
vote
1 answer

Using dcast to cast a wide format when the variables per time period are not uniquely specified

I would like to convert this csv file into a long format. It currently look as follows: Every ID is listed 1 time for each years, so a total of 7 times. What I would like to do is to for each ID have one row, where the variables are listed as…
Tom
  • 2,173
  • 1
  • 17
  • 44
1
vote
2 answers

Elegant solution for casting (spreading) multiple columns of character vectors

I want to transforms a data frame with contact information with of a for a list of municipalities in which similar information such as e.g. phone number appears in multiple columns. I have tried using both reshape2::dcast() as well as…
1
vote
1 answer

Recast in R gives different value

I have the following dataframe in R DF2<-data.frame("ID"=c("A", "A", "A", "B", "B", "B", "B", 'B'), 'Freq'=c(1,2,3,1,2,3,4,5), "Val"=c(1,2,4, 2,3,4,5,8)) The datframe has the following appearance ID Freq Val 1 A 1 1 2 A 2 2 3 A…
Raghavan vmvs
  • 1,213
  • 1
  • 10
  • 29
1
vote
2 answers

Customise the aggregate function inside dcast based on the max value of a column in data.table?

I've got a data.table that i'd like to dcast based on three columns (V1, V2, V3). there are, however, some duplicates in V3 and I need an aggregate function that looks at a fourth column V4 and decides for the value of V3 based on maximum value of…
Ankhnesmerira
  • 1,386
  • 15
  • 29
1
vote
0 answers

using dcast (reshape2) to mold data to wide format populates cells with count instead of value

I have a dataframe in long format (https://docs.google.com/spreadsheets/d/15jDW1pCYs7VD6MAH9GHmYrP-zf8WjsGj9F3qVXGijDM/edit?usp=sharing) that looks like this: objectid timestamp code_bbch_surveyed 1: 702509 2018-03-23 NA …
Momchill
  • 417
  • 6
  • 15
1
vote
2 answers

how to dcast in pandas with more than one columns for columns argument

I have the following dataframe import pandas as pd df = pd.DataFrame({'id':[1,2,3,4,5,6], 'id_2':[6,5,4,3,2,1], 'col_1':['A','A','A','B','B','B'], 'col_2':['X','Z','X','Z','X','Z'], 'value':[10,20,30,40,50,60]}) And I want to dcast it, so I use…
quant
  • 4,062
  • 5
  • 29
  • 70
1
vote
2 answers

Calculate value with two columns based on four conditions in R

I have a large dataset uploaded in r (see below for a short version): I want to calculate a value for each Cruiseid, Samplenr, Species and Age (so based on four conditions): Cruiseid Samplenr Species Age Length LK TNumStat TNumLK 197502 …
Suusie
  • 149
  • 9
1
vote
2 answers

Long to wide with different number of rows for each group/ID

I have the following data frame: df <- data.frame(stringsAsFactors=FALSE, ID = c(2016070707, 2016070707, 2016070707, 2017080808, 2017080808, 2017080808, 2017080808), team_name = c("Harlequins",…
Rama
  • 25
  • 4
1
vote
5 answers

How can I merge three columns into one column according to the order of in the three columns

Could you give me an advice, please? I have three columns, e.x.: x y z 0.2 0.5 0.26 0.75 0.58 0.25 0.78 0.86 0.95 0.56 0.75 0.52 0.45 0.47 0.57 0.2 0.58 0.98 Result: And I need only one column with this sequence: xyz x1 …
Jan Nehyba
  • 19
  • 3
1
vote
1 answer

ggplot2: can geom_point work in melted dataframes?

I am kind of beginner in ggplot2. I have this dataframe: df <- data.frame(testno = 1:4, y1 = c(1.2,3.1,4.6,6.7), y2 = c(5,3.2,9.6,8.8)) df$testno <- factor(df$testno) from which I can easily plot: ggplot(df, aes(x = y1, y=y2)) + geom_point() I…
Alex.z
  • 15
  • 3
1
vote
1 answer

Monthly Dummy Variables in dataset

I have a dataset with 10 columns. One of those columns is the date. I want to create dummy variables for every month. How do I go about doing this? Date Col1 Col2 2017-01-09 v 2 2017-05-01 s 7 2018-03-02 …
nak5120
  • 4,089
  • 4
  • 35
  • 94
1
vote
1 answer

melt data.frame in r and store unused columns in a column (separated by commata)

old problem, for new one see below I have a data.frame df<-data.frame("name" = c("A","A","B","C"), "class" = c("ab","cd","cd","ef"), "type" = c("alpha","beta","gamma","delta")) > df name class type 1 A ab…
enroute
  • 183
  • 9
1
vote
2 answers

Moving data long to wide with dcast

I've been on Stack Overflow for the past few days trying to get a solution to this issue I'm having. I'm analyzing data received from the National Student Clearinghouse, specifically the graduations. So I have some dummy data df <-…
tangerine7199
  • 443
  • 2
  • 8
  • 24
1
vote
1 answer

Reshape data in R using dcast

I have the following data library(reshape2) d <- data_frame( Quart = c("Q1", "Q2", "Q3", "Q4", "Q4", "Q1","Q4","Q1", "Q2", "Q3"), var1 = c(1,0,1,1,1,0,2,3,0,1), var2= c(1,0,1,1,1,0,1,0,1,0), …
Mrmoleje
  • 453
  • 1
  • 12
  • 35