similar to: Converting data.frame from long to wide format

Displaying 20 results from an estimated 20000 matches similar to: "Converting data.frame from long to wide format"

2011 Sep 09
4
reshape data from long to wide format
This is my reproducible example: example<-structure(list(SENSOR = structure(1:6, .Label = c("A", "B", "C", "D", "E", "F"), class = "factor"), VALUE = c(270, 292.5, 0, 45, 247.5, 315), DATE = structure(1:6, .Label = c(" 01/01/2010 1", " 01/01/2010 2", " 01/01/2010 3", " 01/01/2010
2011 May 22
2
Convert dataframe with two factors from wide to long format
I know how to convert a simple dataframe from wide to long format with one varying factor. However, for a dataset with two factors like the following, Subj T1_Cond1 T1_Cond2 T2_Cond1 T2_Cond2 1 0.125869 4.108232 1.099392 5.556614 2 1.427940 2.170026 0.120748 1.176353 How to elegantly convert to a long form as Subj Time Cond Value 1 1 1 0.125869 1
2012 Jul 25
2
reshape -> reshape 2: function cast changed?
Hi, I used to use reshape and moved to reshape2 (R 2.15.1). Now I tried some of my older scripts and was surprised that my cast function wasn't working like before. What I did/want to do: 1) Melt a dataframe based on a vector specifying column names as measure.vars. Thats working so far: dfm <- melt(df, measure.vars=n, variable_name = "species", na.rm = FALSE) 2) Recast the
2012 Aug 07
3
reshape2's dcast() Adds NAs to Data Frame
I need to understand how and why dcast() adds NAs to a data frame that contained no missing values. The database table of chemical concentrations has all missing values removed because they cannot contribute to data analyses. The structure of the R data frame of these data have no NA values, and neither does the data frame resulting from applying the reshape2 melt() function to it. However,
2013 Jan 22
4
Simple use of dcast (reshape2 package)
Suppose I have a small dataframe > aa Target Eaten ID 50 TPP 0 1 51 TPP 1 2 52 TPP 3 3 53 TPP 1 4 54 TPP 2 5 50.1 GPA 9 1 51.1 GPA 11 2 52.1 GPA 8 3 53.1 GPA 8 4 54.1 GPA 10 5 And I want to reshape it into ID TPP GPA 1 1 0 9 2 2 1 11 3 3 3 8 4 4 1 8 5 5 2 10 I realise that
2012 Mar 19
2
Reshape from long to wide
Hi, I'm a total beginner in R and this question is probably very simple but I've spent hours reading about it and can't find the answer. I'm trying to reshape a data table from long to wide format. I've tried reshape() and cast() but I get error messages every time and I can't figure why. In my data, I have the length of two fish from each family. My data table (called
2011 Feb 26
1
Transform a dataset from long to wide using reshape2
I seem to be running into the same problem reported in https://stat.ethz.ch/pipermail/r-help/2010-November/258265.html I cannot seem to transform a dataset from long to wide using reshape2. Clearly I am missing something very simple but a look at the manual and the reshape paper in JSS does not suggest anything. Any advice would be welcome ===========================load
2012 Jul 24
3
Simple reshape problem I am completely missing
I seem to be doing something really stupid or missing something really obvious but what? I have a simple three column data.frame that I would like to reshape to wide preferably using reshape2. An example from http://stackoverflow.com/questions/9617348/reshape-three-column-data-frame-to-matrix looked perfect except I wanted a data frame but it seemed okay. I just changed acast to dcast and it
2013 Jun 26
1
Margins in dcast (reshape2)
Hi, I'd like to get mean values for the margins of my casted data.frame. For the casting I am using dcast() from reshape2. However, when I set the margins parameter (margins=c("grand\_row")) I get following error concerning an unrecognized escape character '\_'. So what is the correct command to get the outermost margins only in reshape2? /johannes [[alternative HTML
2011 Dec 23
2
cast in reshape and reshape2
> library(reshape2) > x = melt(airquality, id=c('month', 'day')) With reshape I can cast with multiple functions: > library(reshape) > cast(x, month+variable~., c(mean,sd)) month variable mean sd 1 5 ozone 23.615385 22.224449 2 5 solar.r 181.296296 115.075499 3 5 wind 11.622581 3.531450 4 5 temp 65.548387
2012 Nov 17
3
Reshaping a dataframe
Seems like this should be easy but I'm struggling a bit. How do I rearrange a data frame to go from the first one to the second shown below ? State Date lbs TX 200701 400 TX 200702 650 TX 200703 950 TX 200704 1000 FL 200701 200 FL 200702 300 FL 200703 500 FL 200704 333 NJ 200701 409 NJ 200702 308 NJ 200703 300 NJ 200704 800 Date TX FL NJ 200701 400 200 409 200702 650
2013 Apr 13
1
Reshaping Data for bi-partite Network Analysis [SOLVED]
Wow ! so many thanks Arun and Rui works like a charm problem solved 2013/4/13 arun <smartpink111@yahoo.com> > Hi, > Try this; > library(reshape2) > res<-dcast(Input,people~place,value.var="time") > res[is.na(res)]<-0 > res > # people beach home school sport > #1 Joe 5 3 0 1 > #2 Marc 0 4 2 0 > #3 Mary
2012 Oct 17
1
Comparing dcast and reshape
I'm in the middle of my own little intellectual exercise comparing dcast() and reshape() and have successfully stumped myself. I want to melt() a data frame, then dcast() it into a new form. After doing so, I want to duplicate the process using reshape(). So far, I can do the melt and cast require(reshape2) Raw <- data.frame(site = c(1, 1, 1, 1, 2, 2, 2, 2), id =
2010 Sep 13
1
Problems with reshape2 on Mac
Hi! I updated to reshape2 yesterday and tried to make it work. Unfortunately, it mainly throws error messages at me (good thing it's reshape2 1.0 and not reshape 2.0). The most recent is: Error in match.fun(FUN) : object 'id' not found When I manually create an object 'id', it says: Error in get(as.character(FUN), mode = "function", envir = envir) : object
2013 Jun 05
2
reshape2 issue continued
Hi again all, Several replied ASAP that I also needed reshape loaded and not just reshape2. Hmmm tried that and I had some output but not the correct format. What I need is to run simulations of time overlap between species as per the simulation program data input constraints: The basis for the simulations is a species by _time-use matrix in which species are arranged in rows, and time
2011 Aug 08
1
Help on reshape2 data frame rearrangement
Dear help list: I am trying to reshape a data frame from long to wide format and with a reduced variable list using reshape2. The original data frame format is: Site Obs_no LengthSite 1 Obs 1 10Site 1 Obs 2 13Site 1 Obs 3 14.........Site 2 Obs 1 5Site 2 Obs 2 7Site 2 Obs 3 9 Site and Obs_no are factors and Length is a numeric variable. There are 15
2012 Jul 03
2
NADA Data Frame Format: Wide or Long?
I have water chemistry data with censored values (i.e., those less than reporting levels) in a data frame with a narrow (i.e., database table) format. The structure is: $ site : Factor w/ 64 levels "D-1","D-2","D-3",..: 1 1 1 1 1 1 1 1 ... $ sampdate: Date, format: "2007-12-12" "2007-12-12" ... $ preeq0 : logi TRUE TRUE TRUE TRUE TRUE
2011 Feb 23
1
Fwd: Re: sum data from data.frame in a matrix
Hi Dennis, Thanks for your quick response and sorry for not being clear. That helped, but I need an actual matrix of e.g., 12 x 12 and those functions give me a matrix with only the "filled" locations. I need a 12 by 12 matrix with sums (0 if there's not data and the actual sum where there is) as follows: 1 2 3 4 5 6 7 8 9 10 11 12 1 0 0 0 . . . . . . 0 0 0 2 0 0 0 . 3 0
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
2011 Aug 08
1
Reshape2 sytax
Hi Hadley et all, I am struggling with reshape2 and melt works and melt_check (filtered151) seems fine My cast command was acast (filtered151, Time ~ Species ~ Number) > melt_check (filtered151) Using time, Species as id variables $id [1] "time" "Species" $measure [1] "Number" When I execute cast the data matrix is in the correct order but the data