Displaying 20 results from an estimated 7000 matches similar to: "Length as fun.aggregate in cast function of reshape package: unexpected error"
2012 Mar 20
2
Reshaping data from long to wide without a "timevar"
Hello All,
I was wondering if it's possible to reshape data from long to wide in R without using a "timevar". I've pasted some sample data below along with some code. The data are sorted by Subject and Drug. I want to transpose the Drug variable into multiple columns in alphabetical order.
My data have a variable called "RowNo" that functions almost like a
2008 Jun 17
1
re sultant column names from reshape::cast, with a fun.aggregate vector
try this:
scores.melt = data.frame(grade = floor(runif(100, 1,10)), variable =
'score', value = rnorm(100));
cast(scores.melt, grade ~ variable, fun.aggregate = c(mean, length))
it has the nice column names of:
grade score_mean score_length
1 1 0.08788535 8
2 2 0.16720313 15
3 3 0.41046299 7
4 4 0.13928356 13
...
but
2011 Dec 18
1
Identifying records with the correct number of repeated measures
Dear list,
I have a dataset where we sampled multiple individuals either 1 or 9
times. Our measurement variable is 'Delta13C' (see below sample
dataset). I cannot figure out how to efficiently use a vector command
(preferably) or a loop to create a new vector of the names of the
individuals sampled 9 times. Note that the 'FeatherPosition' variable
will only be "P1" for
2008 Jul 30
1
bug in 'margins' behavior in reshape - cast
according to the documentation of the cast function in the reshape function,
I would expect this bit of code from the examples to calculate marginal
means over only the 'diet' variable.
#Chick weight example
names(ChickWeight) <- tolower(names(ChickWeight))
chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE)
cast(chick_m, diet + chick ~ time, mean, margins="diet")
But,
2010 Jul 12
1
long to wide on larger data set
I have a data set that has 4 columns and 53860858 rows. I was able to
read this into R with:
cc <- rep("character",4)
myData <- read.table("myData.csv",header=FALSE,skip=1,colClasses=cc,nrow=53860858,sep=",")
I need to reshape this data from long to wide. On a small data set the
following lines work. But on the real data set, it didn't finish even
when I
2010 Aug 16
1
Problem with cast {reshape}: Error in match.fun(FUN) : could not find function "Negate"
Dear All
I'm having problem with some script which worked a few months ago (on a
different computer that might well have had a different version of R
installed, so perhaps it has to do with the old version of R?):
library(reshape)
Loading required package: plyr
> tble.data <- melt.array(interp, varnames=c("tme","lon","lat"))
>
> allyrs.interp <-
2008 Feb 12
3
fun.aggregate=mean in reshape
Hi all,
We are facing a problem while introducing ourselves to Reshape package
use. Melt seems to work fine, but cast fails when we use mean as
fun.aggregate. As you see here, length and sum work fine, but mean
throws this same error whatever dataset we use.
> cast(aqm, month ~ variable, length)
month ozone solar.r wind temp
1 5 26 27 31 31
2 6 9 30 30
2008 Nov 26
1
Reshape with var as fun.aggregate
I used to be able to use variance for fun.aggregate, but since I
upgraded from R 2.6 to 2.7 (Ubuntu hardy to intrepid), it no longer
works.
> library("reshape")
> data("french_fries")
> ffm <- melt(french_fries, id=1:4, na.rm = TRUE)
> cast(ffm, rep ~ treatment, length)
rep 1 2 3
1 1 579 578 575
2 2 580 579 580
> cast(ffm, rep ~ treatment, mean)
2012 Mar 30
3
Adding text for written comments to bottom of graphs
Hello All,
Recently developed the code below for graphing patterns of chemotherapy administration. As someone just starting to use R in their work, I managed to figure out some parts of the code but needed help with others.
setwd("N:/Regimen Coding/0906/Plots Test")
getwd()
TestData <- structure(list(profile_key = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3), line = c(1, 1,
2012 Mar 22
4
Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Hello All,
Want very much to learn how to plot patient drug timelines. Trouble is I need to figure out how to do this today. So not much time for me to struggle with it. Hoping someone can just help me out a bit.
Below are some sample data and code that produces what I think is the beginning of a very nice graph.
Need to alter the code to:
1. Get the lines for the drugs to appear on the
2009 Jul 06
2
ReShape chicks example - line plots
Hi,
In the examples from the ReShape package there is a simple example
of using melt followed by cast that produces a smallish amount of
output about the chicks database. Here's the code:
library(reshape)
names(ChickWeight) <- tolower(names(ChickWeight))
chick_m <- melt(ChickWeight, id=2:4, na.rm=TRUE)
DietResults <- cast(chick_m, diet + chick ~ time)
DietResults
My challenge
2010 Feb 08
1
R ggplot2 legend text left justify
In ggplot2 how do you justify the legend text ?
In the example below the opts(legend.text = theme_text(size =
9,hjust=0)) changes the size of the text OK but it remains right
justified.
> mydata=data.frame(RowID=c("A","B","C"),Name=c("long long long long
long name","short name ","medium medium name"),Speed=c(100,140,120))
>
2009 Mar 06
2
Interaction term not significant when using glm???
Dear all,
I have a dataset where the interaction is more than obvious, but I was asked
to give a p-value, so I ran a logistic regression using glm. Very funny, in
the outcome the interaction term is NOT significant, although that's
completely counterintuitive. There are 3 variables : spot (binary response),
constr (gene construct) and vernalized (growth conditions). Only for the FLC
construct
2020 Sep 24
1
How to use `[` without evaluating the arguments.
Hello R-devel,
I am currently attempting to implement an API similar to data.table wherein single bracket subsetting can accept an unquoted expression to be evaluated in the context of my object.
A simple example from the data.table package looks like this:
DT <- data.table(col1 = c('a', 'b', 'c'), col2 = c('x', 'y', 'z'))
DT[col1 ==
2011 Apr 27
6
Assignments inside lapply
Dear all I would like to ask you if an assignment can be done inside a lapply statement.
For example
I would like to covert a double nested for loop
for (i in c(1:dimx)){
for (j in c(1:dimy)){
Powermap[i,j] <- Pr(c(i,j),c(PRX,PRY),f)
}
}
to something like that:
ij<-expand.grid(i=seq(1:dimx),j=(1:dimy))
unlist(lapply(1:nrow(ij),function(rowId) { return
2009 Jul 10
2
ReShape/cast question - sum of value in table
Hi,
I've tried to capture the basics of this problem I'm having. Been
working on this for a couple of days and just cannot get past it. As a
test of this list software I've attached is a small text file zipped
up. I hope it gets through but if it doesn't I'll post the actual text
which is only 26 lines. Put it somewhere sensible and change the first
line in the code to point
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 Mar 07
1
SELECT CASE in RODBC
Hi all,
I have a problem with a variable created by a SELECT CASE statement. See
the code below.
I would like the variable "event" to be a character variabel as I want to
UNION my two SELECTs - and the "event"-variable is a character variable in
the first SELECT result.
I have tried different ways:
* used ' ' in stead of " " around the string I want as the
2009 Apr 07
2
Using as.formula() with the reshape package cast
I am trying to use the "cast" function from the reshape package, where the
formula is not passed in directly, but as the result of the as.formula()
function.
Using reshape v. 0.7.2
I am able to properly melt() by data with:
> molten <- melt(x, id=1:2)
then I can properly cast with this:
> cast(molten, days ~ variable)
but if I try
> cast(molten,
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