similar to: Generating new variable based on values of an existing variable

Displaying 20 results from an estimated 30000 matches similar to: "Generating new variable based on values of an existing variable"

2008 Aug 27
3
Calculating total observations based on combinations of variable values
Hello: As someone making the move from STATA to R, I'm finding it difficult at times to perform basic tasks in R, so forgive me if I've missed an obvious and easily obtained solution to my problem. I've searched the help guides and the archives and have not been able to find a solution that works. I have a data frame with thousands of observations that looks something like this:
2011 Jun 09
2
Problem with a if statement inside a function
I have a really long functions, and at the end of the function, I am using a if statement to tag certain keywords based on whether they have certain values contained in them. However, the if statement doesn't seem to work. When I had split up the commands into various functions, it worked fine, but I'm not sure what going on now that it's combined into a single function. myfunc
2007 May 21
1
help with this indexing
Hi all, Let's say I have a long data frame and a short one, both with three colums: $east, $north, $value And I need to fill in the short$value, extracting the corresponding value from long$value, for coinciding $east and $north in both tables. I know the possibility: for (i in 1:length(short$value)){ short$value[i] <- long$value[long$east==short$east & long$north==short$north] } How
2008 Sep 17
3
Stacked Area Plot
Hi: I've searched the archives and the Internet for hours but have yet to find a way to do stacked area plots (like the kind in Excel) in R. I think that polygon may work but it would require a bit of manipulation of my data. I was hoping for an easier way. An example of what I'm trying to do can be found here: http://jcharts.sourceforge.net/samples/stackedArea.html Thanks, Josip
2004 Nov 14
2
Exporting to file: passing source name to file name in loop
Hi, I'm having a mental block as to how I can automatically assign filenames to the output of the following code. I am wishing to create a separate .png file for every image created, each of them having a sequential filename ie "sourcefile_index.png" so that I can create a movie from them. Please could someone tell me where I am going wrong? the following code works fine and
2011 Dec 12
3
windrose color ramp issue
Greetings! I'm having an issue with the windrose produced by the windrose function from the circular package. For our weather stations in North Carolina I'm helping with a script which takes hourly wind speed and direction data to create windroses for our end users. One of the stations in the mountains frequently reaches wind speed of 40 to 60 mph and in storms can reach wind speed over
2008 Oct 01
3
Change color of plot points based on values of a variable
Dear R users: I have run a logistic regression, used Gelman et al.'s car package to simulate the parameter estimates of that model, and have plotted the probability (using Gelman et al.'s invlogit() function) of the dependent variable being 1 given the value of a particular independent variable is at its mean. The plot has probabilities on the y-axis and the number (1-1000) of the
2004 Aug 22
1
latitude longitude data
Dear R-helpers, I get GPS readings with bug counts (bugs meaning insects in this case) made along rows in crop fields and use these to make maps of bug distribution. The GPS readings are not quite accurate enough for my purpose, so since I know what row each reading is made in, I adjust the latitudinal coordinate using: grd<-lm(lat~lon+Row,data)
2008 Dec 10
2
Confusion with Converting Factors to Dates using as.date
Dear R-Helpers: I'm having a problem getting dates into the correct format. I have a data frame, which is based on a .csv file that I imported into R via read.table. R has converted my date variables to factors; when I use the as.Date command, most of the values are converted "correctly" (and by this I guess I mean converted "as I wish them to be") but some have not been.
2010 Mar 05
2
How to assign week numbers to a time-series
Hello everyone, My progress has stalled on finding a way of creating a somewhat complicated variable to add to my existing dataframe and I am hoping one of you could help me out. The dataframe below contains only a fraction of the data of my complete dataframe, but all of the variables. What I want to do is add another variable named 'WEEK' to this dataframe that is assigned 1 for row 1
2010 May 12
1
slot assignment in S4 classes
Hi R friends,   I'm still studying S4 classes and I have a question about slot assignment. Why would I have to use a special setter method [example 2 below] if I can assign data to a slot directly when I call new() [example 1 below]?   ## first way to do it (the idiosyncratic way?) setClass(Class = "TestClass", representation = representation(myDf = "data.frame"))
2007 Sep 04
3
variable format
Okay, I want to do something similar to SAS proc format. I usually do this... a <- NULL a$divisionOld <- c(1,2,3,4,5) divisionTable <- matrix(c(1, "New England", 2, "Middle Atlantic", 3, "East North Central", 4, "West North Central", 5,
2005 Jun 25
1
Confidence interval bars on Lattice barchart with groups
I am trying to add confidence (error) bars to lattice barcharts (and dotplots, and xyplots). I found this helpful message from Deepayan Sarkar and based teh code below on it: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/50299.html However, I can't get it to work with groups, as illustrated. I am sure I am missing something elementary, but I am unsure what. Using R 2.1.1 on various
2008 Oct 13
3
lattice panel question
Dear R users, How to change lattice panel label/text from the automatically generated label (based on the conditioning) to our own set of label? for example: someStuff <- data.frame(area = rep(c("SOUTH", "NORTH", "EAST", "WEST"), each = 25), group = rep(c("A","B","C","D"), each = 5),
2008 Jun 23
3
subset with multiple criteria
This should be theoretically very simple, but I dont get the elegant answer (without looping). I've got a long (thousands of rows) data frame: > E.coor[1:10,] east north dat 1 582650 4248850 0.8316848 2 582750 4248850 0.7230272 3 582850 4248850 0.3250818 4 582950 4248850 0.6144006 5 583050 4248850 0.8706312 6 583150 4248850 0.2149651 7 583250 4248850 0.1659519 8
2011 Oct 22
2
Expanding rows of a data frame into multiple rows
The setup: I have a data frame where one column is in list mode, and each entry contains a vector of varying length. I want to expand this into a data frame with one row for each member of the list-mode column (the other values being replicated) For example, an example input and the desired output would be: input <- data.frame(site = 1:6, sector =
2009 Jan 13
1
Drawing Polygons with xyplot in lattice
Hello: I've come to a dead-end in my search for a solution to a graphing problem that I am encountering. I have used xyplot (from the lattice package) successfully to plot 36 time-series plots (lines) of under-5 mortality for a set of countries in Sub-Sarahan Africa. What I would now like to do is to add vertical bands (rectangles) that correspond to time-periods during which each of the 36
2005 Dec 08
2
'mean' and 'sd' calculations do not match
Dear list, I am using R 2.1.1 on a Fedora 3 Linux, 32 bit PC. If I compute the aggregated mean and the standard deviation I get standard deviation values for factors where the mean was not computed. It seems to me that this is somehow related to the NA values. But I don't quite understand what is going wrong? Could it be related to the data import already? Some of the imported data got the
2007 Aug 16
3
e c30ac536947f7330943f8de9c33f70ef2d5994e7
e, elemental, is a stack for the data web there are 4 components: earth, air, fire, water earth is a pure-ruby RDF triple-store, with a fs backend. no dependencies on 3rd party databases, just add filesystem (tm). theres also a ram backend built with the Mongrel URI-classifier trie as the primitive datastructure. from these two it should be easy to extrapolate how to write a memcached/hadoop
2009 Jan 27
1
Data Frame Manipulation: Time Series
Dear R Helpers: I have a data set where the unit of observation is country-year. I would like to generate a new data set based on some inclusionary (exclusionary) criteria. Here is an example of the type of data that I have. df<-data.frame(cbind("country"=c(rep("Angola", 9), rep("Burundi", 7), rep("Chad", 13)), "year"=c(1975:1983, 1989:1995,