similar to: Adding a new column to data frame (recoding)

Displaying 20 results from an estimated 8000 matches similar to: "Adding a new column to data frame (recoding)"

2000 Mar 26
2
hist2d() function in R?
Dear R users, I am just starting with R (v. 1.0.0) and I use Vehables & Ripley's MASS book for examples. In the intro session, there is an example of a 2D histogram on an 8x8 grid: x <- rnorm(1000) y <- rnorm(1000) contour(hist2d(x,y,,,8,8)) R complains: Error in contour(hist2d(x, y, , , 8, 8)) : couldn't find function "hist2d" I looked for hist2d() in the
2000 Jun 13
3
Question on closure (lexical scoping) and encapsulation
Dear R users, I have two related questions about scoping and data encapsulation. One is fairly specific - I am looking at "scoping.R" which is used in demo(scoping) - it's an example of lexical scoping and encapsulation. Where is the 'total' stored? It is not an attribute in 'ross' or 'robert' however, functions like balance() have access to it. Is it more
2000 Dec 14
1
How do I track a segfault?
Dear R users, I have to catch a nasty bug and would appreciate any advice or help! I get a segfault (core dumped) that happens in one of my own functions. The problem is, it does not happen most of the time, only sometimes, so it's very hard to reproduce. Or it may run ok in interactive mode, but bug out in batch mode. Also, it tends to happen more on the slower of my 2 machines (PII 266),
2011 Aug 31
1
Recoding observations in all columns of a data frame.
Dear all, Suppose I have a data frame like this: [code] var1 <- c(1,999,2) var2 <- c(999,1,2) var3 <- c(1,2,999) example <- data.frame(var1,var2,var3) [/code] I want to replace all 999 to NA in all observations in all columns. I know how to do it in each individual column. [code] example$var1[example$var1==999] <- NA [/code] I think it can be done with a for loop. [code] for
2003 Nov 11
2
Test for new page
Dear R experts, I am writing a multi-page PDF file and would like to put a header on each page. Is there a way to test a graphic device to see if a new page is started (so that I know when to write the header)? I could simply count the plots made (each page has the same number of plots), but wanted to see if a more general solution is available. Thank you, Aleksey -- Aleksey Naumov GIS
2003 Jun 22
1
Using weighted.mean() in aggregate()
Dear R users, I have a question on using weighted.mean() while aggregating a data frame. I have a data frame with columns Sub, Length and Slope: > x[1:5,] Sub Length Slope 1 2 351.547 0.0025284969 2 2 343.738 0.0025859390 3 1 696.659 0.0015948968 4 2 5442.338 0.0026132544 5 1 209.483 0.0005304225 and I would like to calculate the weighted.mean of Slope, using Length
2010 Nov 16
4
Simple error handling in R
Hi R experts, I am looking for a simple error handling approach, whereby I could stop function execution with a customized error message. For example: for (i in 1:10) { if (i == 5) # I'd like to be able to stop right here with an error message I have complete control over } The problem with stop() is that I cannot control completely what gets printed to the terminal, even with
2002 Oct 26
3
Using the Search Engine & Keywords
Dear R experts, Can anyone running R on Linux share how they use the "Search Engine & Keywords" page of R documentation? I cannot do any javascript on this page, either searching for a term or following the keyword links. I tried Konqueror (3.0.4, with javascript globally enabled), Mozilla (1.1), and Galeon (1.2.5), but none of them do anything... Sorry, I don't know
2005 Apr 30
1
legend(): how to put variable in subscript?
Dear List, I would like to plot a simple legend with two math expressions, e.g. plot(0) legend(1, 0.5, expression(sigma[i], sigma[j])) The difficulty is that i and j should be variables rather than strings "i" and "j". In other words I'd like to do something like: i = "A" j = "B" legend(1, 0.5, expression(sigma[i], sigma[j])) and have "A"
2000 Nov 17
2
Randomly selecting n (unique) elements out of vector of length m...
Dear R users, I wonder if there is a simple way to select a random and non-overlapping subset of a vector? Say, I need to randomly select 10 out of 100 numbers in a vector V. By "non-overlapping" I mean that a number in any position in V (V[1]...V[100]) should be selected at most once (i.e. selection without recycling). I could simplu use a uniform distribution to generate selection
2010 Mar 05
2
Sweave and optional document sections
Dear R and Sweave users, Is there a way to have optional sections in a Sweave-generated report document, complete with section header(s), text and code chunks? In other words, I'd like for my report to include or omit certain sections based on the data itself. For example, If I examine the input dataset early on in the report and set a variable has_daily_data = TRUE, then I'd like to
2012 Apr 12
4
Recode Variable
Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120412/74331e9a/attachment.pl>
2012 Sep 11
3
Combine two variables
Hi: I have two variables in a data frame that are the results of a wording experiment in a survey. I'd like to create a third variable that combines the two variables. Recode doesn't seem to work, because it just recodes the first variable into the third, then recodes the second variable into the third, overwriting the first recode. I can do this with a rather elaborate indexing process,
2010 Feb 26
1
Automate generation of multiple reports using odfWeave
Dear R and odfWeave users, I am looking for a way to automate generation of many reports using odfWeave. All reports would use the same input ODT file, the only difference would be in the name of the dataset which will be analyzed in any particular report. Right now, the name of the dataset is hardcoded in the first code chuck in the input file: <<01 get data, echo=TRUE>> station =
2004 Aug 17
5
Bug in colnames of data.frames?
Hi, I am using R 1.9.1 on on i686 PC with SuSE Linux 9.0. I have a data.frame, e.g.: > myData <- data.frame( var1 = c( 1:4 ), var2 = c (5:8 ) ) If I add a new column by > myData$var3 <- myData[ , "var1" ] + myData[ , "var2" ] everything is fine, but if I omit the commas: > myData$var4 <- myData[ "var1" ] + myData[ "var2" ] the name
2008 Jul 16
2
Group level frequencies
Dear List, I have Multi-level Data i= Indivitual Level g= Group Level var1= First Variable of interest var2= Second Variable of interest and I want to count the frequency of "var1" and "var2" on the group level. I found a way, but there must be a much simpler way. data.ml <- data.frame(i=c(1:8),g=as.factor(c(1,1,1,2,2,3,3,3)),var1=c(3,3,3,4,4,4,4 ,4),
2009 Sep 22
3
converting a character vector to a function's input
Hi all, I have been trying to solve this problem and have had no luck so far. I have numeric vectors VAR1, VAR2, and VAR3 which I am trying to cbind. I also have a character vector "VAR1,VAR2,VAR3". How do I manipulate this character vector such that I can input a transformed version of the character vector into cbind and have it recognize that I'm trying to refer to my numeric
2010 Dec 20
2
Turning a Variable into String
I would like to know how to turn a variable into a string. I have tried as.symbol and as.name but it doesnt work for what I'd like to do Essentially, I'd like to feed the function below with two variables. This works fine in the bit working out number of elements in each variable. In the print(sprintf("OK with %s and %s\n", var1, var2)) line I would like var1 and var2 to be
2014 Aug 21
2
pregunta
Buenas noches Javier y José, Estoy en contra de usar attach(), asi que propongo la siguiente alternativa con with(): # paquete require(epicalc) # los argumentos en ... pasan de epicalc:::cc # ver ?cc para mas informacion foo <- function(var1, var2, var3, ...){ or1 <- cc(var1, var2, ...) or2 <- cc(var1, var3, ...) list(or1 = or1, or2 = or2) } # datos x <-
1999 Jan 04
1
Names of data frame columns in an apply
Hi, [some background] I have a dataset which describes a number of subjects doing a "scientific discovery". That is, they have to discover the rules underlying a particular domain. To do so, they have to set the levels of 5 variables which leads to a certain outcome. To identify what kind of "experiments" the subjects did, I want to combine these levels into one variable