similar to: ifelse choices in a data.frame?

Displaying 20 results from an estimated 80000 matches similar to: "ifelse choices in a data.frame?"

2012 Nov 15
4
using ifelse to remove NA's from specific columns of a data frame containing strings and numbers
Hi everyone, I have a data frame one of whose columns is a character vector and the rest are numeric, and in debugging a script, I noticed that an ifelse call seems to be coercing the character column to a numeric column, and producing unintended values as a result. Roughly, here's what I tried to do: df: a data frame with, say, the first column as a character column and the second and
2005 Apr 28
4
wine-20050419 - where to set audio driver type?
Hi, In a completely clean account that's never run Wine before I run wine --version. Wine installs a new .wine directory but this Wine directory has no config file. I looked in the 3 obvious files but none of them seem to have an option for changing between OSS, Alsa and JAck. where do I make this setting change now? Thanks, Mark
2009 Jul 23
1
howto create a list row-by-row as input to function call?
Hi, I'm having trouble within my function CalcPos to get it to call CalcHorz with values from each row. I *think* it's calling CalcHorz with the final values of the inputs and not the values from each row. How can I do this properly in R? The values aa,bb,cc,dd are inputs. CalcPos first calculates V1 and V2 vertically, and then I attempt to call CalcHorz to handle H1, H2 & H3
2010 Jul 20
1
ifelse() and missing values in test conditions
R experts, I have been unable to get the following ifelse statement to work as desired when applied to my data frame. Example: DF$ANYEF <- with(DF,ifelse(PSOUGHT1=='ANY'|PSOUGHT2=='ANY'|PSOUGHT3=='ANY',PEFF,0)) ##### this statement will be replicated 16 times for 16 unique _EF variables ### Basically, I want each ANYEF for each row to equal the corresponding row
2012 Jan 19
3
Establishing groups using something other than ifelse()
Hello all, This is one of those "Is there a better way to do this questions". Say I have a dataframe (df) with a grouping variable (z). This is my base data. Now I know that there is a higher order level of grouping that exist for my group variable. So what I want to do is create a new column that express that higher order level of grouping based on values in the sub-group (z in this
2011 Jul 30
3
ifelse returns
Greetings R Community, I am working with the ifelse function and it is returning something unexpected. In the code the line with the MODE1 assignment the output is a vector [1] 4 5 6 but when I put the MODE1 object into the ifelse function [R}'s output for MODE1 is the first number from the string (4). Why is this? Given the supplied vector of x I would assume both the MODE1 and ifelse()
2006 Nov 21
2
using nested ifelse and rowSums to create new variable?
Dear R-help community, If I have a data.frame df as follows: > df x1 x2 x3 x4 x5 x6 1 5 5 1 1 2 1 2 5 5 5 5 1 5 3 1 5 5 5 5 5 4 5 5 1 4 5 5 5 5 1 5 2 4 1 6 5 1 5 4 5 1 7 5 1 5 4 4 5 8 5 1 1 1 1 5 9 1 5 1 1 2 5 10 5 1 5 4 5 5 11 1 5 5 2 1 1 12 5 5 5 4 4 1 13 1 5 1 4 4 1 14 1 1 5 4 5 5 15 1 5 5 4
2009 Sep 20
2
Date/Time to date & time
Hi, Can strptime (or some other function) help me turn the following column of a data.frame into two new columns, one as date and the other as time, preserving the AM/PM value? Thanks, Mark > B ENTRY DATE 1 3/23/2009 6:30:00 AM 2 3/23/2009 6:30:00 AM 3 3/23/2009 6:39:00 AM 4 3/23/2009 6:39:00 AM 5 3/23/2009 6:48:00 AM 6 3/23/2009 6:48:00 AM 7 3/23/2009 7:00:00 AM
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 Jun 22
1
applying ifelse to dataframe
The following dataframe will illustrate the problem DF<-data.frame(name=rep(1:5,each=2),x1=rep("A",10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1)) DF$x3[5]<-50 # we have a data frame. we are interested in the columns x2,x3,x4 which contain sparse # values and many NA. DF name x1 x2 x3 x4 1 1 A 10 NA 20 2 1 A 11 NA 21 3 2 A 12 NA 22 4 2 A 13 NA
2005 Oct 23
1
Re: winebuild problems - wine-20050930 [SOLVED]
Sorry for the noise. On 10/23/05, Mark Knecht <markknecht@gmail.com> wrote: > On 10/23/05, Mark Knecht <markknecht@gmail.com> wrote: > > Hi, > > Does anyone know what happened to the --debug option in winebuild? > > It seems to have disappeared in more recent versions of Wine. > > > > I am attempting to build a program that uses winebuild with
2009 Jul 22
5
Multi-line comments?
Hi, I looked in the language definition and was surprised. Is there really no multi-line/block comment defined in R? I wanted to comment out 20 lines that I'm moving to a function but didn't want to delete them. Is there no defined way to get around using a # on each of the 20 lines? Thanks, Mark
2009 Sep 09
3
lag a data.frame column?
Sometimes it's the simple things... Why doesn't this lag X$x by 3 and place it in X$x1? (i.e. - Na's in the first 3 rows and then values showing up...) The help page does talk about time series. If lag doesn't work on data.frame columns then what would be the right function to use to lag by a variable amount? Thanks, Mark X=data.frame(x=seq(1:10)) X$x1=lag(X$x, 3) X
2012 Oct 04
1
R help - Adding a column in a data frame with multiple conditions
Hi, I am trying to add a column of numbers to a data frame in R with multiple conditions. Here is a simplified example df: [A] [B] [C] [D] [E] [1] 1 X 90 88 [2] 1 Y 72 70 [3] 1 Z 67 41 [4] 2 X 74 49 [5] 2 Y 42 50 [6] 2 Z 81 56 [7] 3 X 92 59 [8] 3 Y 94 80 [9] 3 Z 80 82 I would like column [E] to have a certain value (found either in [C] or [D]) based on conditions in columns [A] *and* [B].
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
2008 Oct 22
3
coalesce columns within a data frame
Dear all, I searched the mail archives and the R site and found no guidance (tried "merge", "cbind" and terms like "coalesce" with no success). There surely is a way to coalesce (like in SQL) columns in a dataframe, right? For example, I would like to go from a dataframe with two columns to one with only one as follows: From Name.x Name.y nx1 ny1 nx2 NA
2010 Jul 19
2
error when copy and transform within a data frame
# trying to do a copy and a transform within a data frame, but getting the "arguments imply differing number of rows" error, and I'm not sure why a=c(1,2,3) b=c(2,3,4) c=c("Yes","No","Yes") d=c("No","Yes","No") df=data.frame(a,b,c,d) # the following works fine! df = transform(df, new=sapply(df[,c(1,2)], FUN = function(x)
2009 Aug 28
2
new data.frame summed by date
Hi, I wonder if someone can suggest how to create a new data.frame Y from X where X$PL_Pos is summed by each unique X$MyDate. Y should end up with two (or more) columns Y$MyDate and Y$PL_Sum with its value being the cumsum of all the values in X for that date. - a 'daily cumsum'. Thanks, Mark TStoDate = function (TSDate) { X = strptime(TSDate + 19e6L, "%Y%m%d")
2009 Jul 02
2
Plot two graphs with different ranges in one
Hi, I'm trying to plot two variables in one graph. One ranges between 0 and 1, while the other ranges between 50 and 500. Can I plot them in one graph with similar scale? Thanks Harry [[alternative HTML version deleted]]
2012 Nov 09
3
General function to substitute values in a data frame
Hi R users, I need a way to substitute the values 10:31 to the letters A:V (i.e 10=A, 11=B, ..., 31=V) in a data frame. For example: > y<-c(10,11,12,13) > z<-c(28,29,30,31) > df<-data.frame(y,z) > df y z 1 10 28 2 11 29 3 12 30 4 13 31 Then I would substitute it and obtain a data frame like this as a result of the function: >