similar to: Using functions to change values in a data.frame

Displaying 20 results from an estimated 30000 matches similar to: "Using functions to change values in a data.frame"

2009 Jul 01
1
running count in data.frame
Hi, I need to keep a running count of events that have happened in my data.frame. I found a document called usingR that had an example of doing this for random coin flips and I tried to modify it. It seems to sort of work in the beginning, but then it stops and I don't understand why. I'm trying to duplicate essentially the Excel capability of =SUM($A$1:$A(Row number)) The example
2009 Jul 01
2
?max (so far...)
Hi, I have a data.frame that is date ordered by row number - earliest date first and most current last. I want to create a couple of new columns that show the max and min values from other columns *so far* - not for the whole data.frame. It seems this sort of question is really coming from my lack of understanding about how R intends me to limit myself to portions of a data.frame. I get the
2012 Nov 09
3
if between 500-600 give 550
I have a data frame somewhat like this: myframe <- data.frame (ID=c(2,3,4,5), Hunger =c(415,452,550,318 )) myframe Now I would like to add a column to the right which summarizes the values for Hunger somewhat to reduce the number of values: If the values for Hunger are between 300-400 I would like to insert the number 350, between 400-500 insert 450 between 500-600 insert 550 Does
2010 Dec 23
1
with(data.frame,ifelse(___,___,___))
Hello, All, Mac OS 10.6.5 R64 2.11.1 This works as expected: f1 = c(0.084, 0.099, 0) data= data.frame(f1) data$f1=with(data,ifelse(f1==0, 0.0001, f1)) data f1 1 0.0840 2 0.0990 3 0.0001 Substituting ''f1==0'' with ''T'' produces the expected result: f1 = c(0.084, 0.099, 0) data= data.frame(f1) data$f1=with(data,ifelse(T, 0.0001, f1)) data f1 1 1e-04
2011 Jul 22
1
Summing daily values by weekday and weekend
(Sorry for reposting. Please delete previous msgs. Thanks!) Hi, all Here I created a data frame like mydates<- seq(as.Date("2010-05-29"), length = 43, by = "day") myvalues<-runif(43,0,1) myframe<-data.frame(dates=mydates, day=weekdays(dates), value=myvalues) dates day value 1 2010-05-29 Saturday 0.14576143 2 2010-05-30 Sunday 0.37669604
2008 Mar 31
2
Mouse motion example - help
Hi, I am trying out this example adapted from the wxpython book, but the mouse motion event does not seem to be captured right. What am I doing wrong? Thanks warrior # code below require ''wx'' class MyFrame < Wx::Frame def initialize super(nil, -1, "My Frame", :size => [300,300]) @my_panel = Wx::Panel.new(self, -1) evt_motion(){ |event|
2011 Mar 30
2
summing values by week - based on daily dates - but with some dates missing
Dear everybody, I have the following challenge. I have a data set with 2 subgroups, dates (days), and corresponding values (see example code below). Within each subgroup: I need to aggregate (sum) the values by week - for weeks that start on a Monday (for example, 2008-12-29 was a Monday). I find it difficult because I have missing dates in my data - so that sometimes I don't even have the
2009 Jul 19
3
ifelse choices in a data.frame?
Hi, In my data.frame I wanted to essentially write If(Test) c*d else c+d but that doesn't work. I found I could do it mathematically, but it seems forced and won't scale well for nested logic. I have two examples below writing columns e & f, but I don't think the code is self-documenting as it depends on knowing that Test is a TRUE/FALSE. Is there a better way to do the
2010 Jul 12
1
S4 class extends "data.frame", getDataPart sees "list"
R-Devel: When I get the data part of an S4 class that contains="data.frame", it gives me a list, even when the "data.frame" is the S4 version: > d<-data.frame(x=1:3) > isS4(d) [1] FALSE # of course > dS4<-new("data.frame",d) > isS4(dS4) [1] TRUE # ok > class(dS4) [1] "data.frame"
2012 Sep 26
2
average environmental data if AnimalID and Time is duplicated
Hello, I tried for about three hours now to solve this problem but I can't figure it out. I am sure someone knows how do it. At least I hope so. I have a data frame somewhat like this: myframe <- data.frame (ID=c("Ernie", "Ernie", "Bert", "Bert"), Timestamp=c("24.09.2012 09:00", "24.09.2012 09:00", "24.09.2012 10:00",
2017 Aug 19
0
My very first loop!! I failed. May I have some start-up aid?
Thank you for providing the example code... for the request of running it multiple times it would have helped if you could have confirmed that the example ran through without errors... there were a lot of mistakes in it. Look into using the reprex package to check your example next time. I don't do this kind of analysis... I really don't know what to expect from the functions. The
2010 Aug 13
3
transforming dates into years
Hello! If I have in my data frame MyFrame a variable saved as a Date and want to translate it into years, I currently do it like this using "zoo": library(zoo) as.year <- function(x) as.numeric(floor(as.yearmon(x))) myFrame$year<-as.year(myFrame$date) Is there a function that would do it directly - like "as.yearmon" - but for years? Thank you! -- Dimitri
2005 Aug 17
7
Volunteer requested: Implement SplitterWindow
About a year ago (ouch!), Robert Carlin submitted a ported version of the wxPython demo/sample. I hoped to include it in wxruby2, but it relies on SplitterWindow, which isn''t in wxruby2 yet. I tried to implement SplitterWindow myself, but got such strange results that I''m thinking I did something wrong. Even though the generated C++ code specified a variable number of
2006 Mar 30
2
Plotting a segmented function
This might be a trivial question, but I would appreciate if anybody could suggest an elegant way of plotting a function such as the following (a simple distribution function): F(x) = 0 if x<=0 =(x^2)/2 if 0<x<=1 =2x-((x^2)/2)-1 if 1<x<=2 =1 if x>2 This is just an example. In this case it is a continuous function. But how to do it in general in an elegant way.
2012 Oct 25
2
mean of a value of the last 2 hours
Hello, I have a data frame somewhat like that: myframe <- data.frame (ID=c("Ernie", "Ernie", "Ernie", "Bert", "Bert", "Bert"), Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00", "24.09.2012 11:00"), Hunger=c(1,1,1,2,2,1) ) myframestime <- as.POSIXct (strptime(as.character(myframe$Timestamp),
2010 Sep 27
1
conditional assignment of colors in xyplot()
# Dear R Community, # I have this data frame: df1 <- data.frame( F1 = factor( c( rep("D1",12),rep("D2",12),rep("D3",12) ) ), F2 = factor( rep( rep( paste("O",1:6,sep=""), rep(2,6) ), 3) ), F3 = factor( rep( c("V1","V2"), 18 ) ), S1 =
2010 Jan 12
3
How to get minimum value by group
I'd like to get a long data set of minimum values from groups in another data set. The following almost does what I want. (Note, I'm using the word factor differently from it's meaning in R; bad choice of words) myframe = data.frame(factor1 = rep(1:2,each=8), factor2 = rep(c("a","b"),each=4, times=2), factor3 = rep(c("x","y"),each=2, times=4),
2011 Feb 08
3
Keep date, strip time?
I have hundreds of CSV files coming in from another program that have a text field representing the date & time combined together. I need to strip the time and keep the date. How could I do that? In the example below, on the first line I need to keep the 6/15/2009, turning it into a date that R recognizes, but I need to throw away the time portion completely. >
2012 Nov 27
5
loop with date
Hello, I tried to construct my very first loop today and completly failed :-( Maybe someone can help me? I have a dataframe somewhat like this one: myframe <- data.frame (Timestamp=c("24.09.2012 09:00", "24.09.2012 10:00", "24.09.2012 11:00", "25.09.2012 09:00", "25.09.2012 10:00", "25.09.2012
2017 Aug 19
4
My very first loop!! I failed. May I have some start-up aid?
Dear all, I have a data similar to this: myframe<- data.frame (ID=c("Ernie", "Ernie","Ernie","Ernie"), Timestamp=c("24.09.2012 08:00", "24.09.2012 09:00", "24.09.2012 10:00", "25.09.2012 10:00"), Longitude=c("8.481","8.482","8.483","8.481"),