similar to: If statement - copying a factor variable to a new variable

Displaying 20 results from an estimated 50000 matches similar to: "If statement - copying a factor variable to a new variable"

2007 Feb 01
2
Losing factor levels when moving variables from one context to another
Hi, there I'm currently trying to figure out how to keep my "factor" levels for a variable when moving it from one data frame or matrix to another. Example below: vec1<-(rep("10",5)) vec2<-(rep("30",5)) vec3<-(rep("80",5)) vecs<-c(vec1, vec2, vec3) resp<-rnorm(2,15) dat<-as.data.frame(cbind(resp, vecs))
2012 Nov 22
1
Efficiently creating/defining new variables transformations
I would like to add an extension to the current name of a variable to create a new variable that is its sqrt transform. Each piece of the equation below works independently, but the left side definition fails on run. I also tried creating the variable name first, but ended up with an object that toString() did not fix. Better ideas? Example 1
2005 Apr 21
2
Deciles and R
Hi everyone, I'm a new R user (if this is a really basic question, please do excuse me...) and I'm having some questions regarding a deciles problem. I have a variable which I need to categorize according to its deciles (X). However, this categorization should be made into another variable (call it NewVar). Ex. for the quartiles case (just for the sake of exposition, since I need
2011 Jan 04
1
Go from CALLINGout to just CALLING
Hello list, how can I go from CALLINGout to just CALLING ? I've tried : exten => s,n,Set(newVAR=${CUT(CALLINGout,,3)}) or exten => s,n,Set(newVAR=$[CUT(CALLINGout,,3)]) But no result : [Jan 4 11:10:12] -- Executing [s at from-S:34] NoOp("SIP/s2-0000003b", "newVAR=") in new stack Asterisk 1.6.10 here. Kind regards, Jonas. -------------- next part
2006 May 24
5
Joining variables
Hello, If I have two variables that are factors or characters and I want to create a new variable that is the combination of both what function can I use to accomplish this? Ex. Var1 Var2 SA100055113 19851113 And I want NewVar SA10005511319851113 Thanks in advance. Cameron Guenther, Ph.D. Associate Research Scientist FWC/FWRI, Marine Fisheries Research 100 8th Avenue S.E. St.
2012 May 11
1
Matching - finding and listing data that is one object but not in another
What is the best way to find out what elements/numbers that are in one object are not in another. I came up with this method, but I'm wondering if there is a more efficient way (and one that doesn't seem so "clunky"). #Example id <- c(1,2,3,4,5,6,7,9,10) example.1 <- data.frame(id) #Second object, this time with an 8 in it. id <- c(1,2,3,4,5,6,7,8,9,10) example.2
2011 May 18
1
assign $y of predict() function output to variable
Hello R-help Below is the output from the predict() function. How can I assign $y to a variable. >predict(function,df2) $x        V1 1   36.28 2   34.73 3   33.74 4   69.87 5   58.88 6   89.44 7   43.97 8   41.94 9   33.34 10  38.47 11  35.16 12  42.94 13  46.76 14  53.24 15  52.43 16  50.40 17  34.42 18  33.22 19  33.24 20  39.60 21  39.32 22  44.71 23  54.03 24  47.48 25  35.42 26  34.78
2005 Apr 14
1
Multiple copies of attached packages
I have noticed that after I ran a batch script multiple times I get multiple copies of a package's name when I call search(). Is this a problem? > search() [1] ".GlobalEnv" "DF" "DF" [4] "DF" "DF" "DF" multiple copies here ... [13] "DF" "DF"
2011 Oct 20
2
Aggregating data help
Hello, I have a dataset with student performance on a math test. There are multiple cases for each student (identified by id) and the concept as a variable. > rtest id test subject grade concept correct tested per_corr year 1 1 83 Mathema 8 8.2.D 1 1 100 2011 2 1 83 Mathema 8 8.3.A 1 2
2003 Oct 13
1
AGI solution to Grandstream BT102 call waiting problem
I'm trying to fix a problem with the GrandStream Budgetone 102. I've been reading the source code, mailing lists and other resources. Here's the scenario and the approach I have been pursuing. I'm having some problems with the AGI calls and I hope someone can give me some clarification. PSTN <---> T1,PRI * <---> Grandstream BT 102 (12)
2009 Feb 27
1
Large 3d array manipulation
I have a large 3 dimensional array of size (243,246,768) The first dimension is Rows, second is columns and the third is Time. So for each row and column, I want to calculate the mean of time steps 1:8, 2:9, 3:10 and so on and assign the values to a new array. For this I am using the following script. for(i in 1:243) { for(j in 1:246) { for(k in 1:768) { newVar[i,j,k] <- mean(
2011 Dec 03
1
Reading multiple text files and then combining into a dataframe
I have a multiple text files, separated by a single space, that I need to combine into a single data.frame. Below is the track I'm on using list.files to capture the names of the files and then lapply with read.table. But I run into problems making a usable dataframe out of the data. #Creating example data in similar format to data I have sub <- rep(1,10) trial <- seq(1,10,1) size
2010 Feb 27
1
New Variable from Several Existing Variables
I am new to R, but have been using SAS for years. In this transition period, I am finding myself pulling my hair out to do some of the simplest things. An example of this is that I need to generate a new variable based on the outcome of several existing variables in a data row. In other words, if the variable in all three existing columns are "Yes", then then the new variable should
2013 May 13
2
reduce three columns to one with the colnames
Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130513/fe848ce7/attachment.pl>
2012 Dec 10
3
equivalent of group command of the egen function in Stata
Dear R listers, I am trying to create a new variable that uniquely identifies groups of observations in a dataset. So far I couldn't figure out how to do this in R. In Stata I would simply type: egen newvar = group(dim1, dim2, dim3) Please, find below a quick example to show what I am dealing with: I have a dataset with 4 variables: var <- runif(50) ## a variable that I want to group
2012 Jul 31
3
Help with NaN when 0 divided by 0
Hi All, I have some data where I am doing fairly simple calculations, nothing more than adding, subtracting, multiplying and dividing. I’m running into a problem when I divide one variable by another and when they’re both 0 I get NaN. I realize that if you divide a non-zero by 0 then you get Inf, which is, of course, correct. But in my case I never get Inf, just NaN because of the structure
2008 Apr 09
1
vectorized way to combine levels of a factor
Hi Gurus: If I have a large dataset of the form of: > x <- data.frame(V1 = runif(10), V2 = sample(c('A','B','C'),10,T)) > x V1 V21 0.2691580 A2 0.8711267 B3 0.2674728 C4 0.3278876 A5 0.1809152 A6 0.2499651 C7 0.9155174 A8 0.8004974 B9 0.7885516 A10 0.9301630 A And I want a V3 that =V2 if V2=A, and =D if V2=B or C. In other words I
2003 Oct 15
2
Example of cell means model
This is an example from chapter 11 of the 6th edition of Devore's engineering statistics text. It happens to be a balanced data set in two factors but the calculations will also work for unbalanced data. I create a factor called 'cell' from the text representation of the Variety level and the Density level using '/' as the separator character. The coefficients for the linear
2009 Jun 24
1
"by" question
Hello all I have a big data frame and I regularly want to break it down into subsets, calculate some new data, and add it back to the data frame. At the moment my technique seems a bit ugly and embarrassing. Something like: result <- by(mydata, mydata$some_factor, function (x) { # do something to create a vector v with length(v) == nrow(x) return(v) }) # now result has a big list, argh...
2004 Sep 08
4
factor always have type integer
typeof applied to a factor always seems to return "integer", independently of the type of the levels. This has a strange side effect. When a variable is "imported" into a data frame, its type changes. character variables automatically are converted to factors when imported into data frames. Here is an example: > v1<-1:3 >