similar to: add factor to dataframe given ranges

Displaying 20 results from an estimated 3000 matches similar to: "add factor to dataframe given ranges"

2006 Apr 28
2
entries that match a regexp
Hi all, I am trying to filter the element of a df that start with "TF", like this: alfa = c(123221,"TF13124",41243,"TF1234",32414,"TF13124","TF14333",2134123,"TF1234") beta =
2008 Feb 28
1
calculate sd for each row on some columns of a dataframe
Hi, I've got a dataframe like this: df = data.frame(a=rnorm(100,1),b=rnorm(100,10),c=rnorm(100,100),d=rnorm(100,-100)) and I want to calculate sd1 for (a,b,c) for each entry, and sd2 for (b,c,d) for each entry. I don't seem to find the answer using aggregate or apply, How can I do this? Thanks in advance, Cheers, Albert.
2006 Jun 21
3
sort matrix by sum of columns
Hi all, I would like to know how can I sort the cols of a matrix by the sum of their elements. a <- matrix(as.integer(rnorm(25,4,2)),10,5) colnames(a) = c("alfa","bravo","charlie","delta","echo") I guess I should use colSums, and then rearrange the matrix somehow according to the result. My idea is to display a "sorted" barplot:
2006 Jun 09
2
barplot dataframes w/ varying dimensions
Hi all, I would like to do a barplot of a dataframe like this one: alfa beta gamma delta qwert 56.5 58.5 56.5 58.5 asdfg 73.0 73.0 43.0 73.0 zxcvb 63.0 63.0 43.0 63.0 yuiop 63.0 63.0 43.0 63.0 with the labels of the rows and columns. I would like to have something that works for dataframes with varying dimensions, and so far I haven't found any way to do it.
2011 Jun 07
1
Adding values to the end of a data frame
Let's say that I'm trying to write a functions that will allow me to automate a process where I examine all possible combinations of various string groupings. Each time I run the one function, I want to include the new values to the end of a data frame. The data frame will basically be one column with a lot of rows. roots <- c("car insurance", "auto insurance")
2011 May 19
1
Creating a "shifted" month (one that starts not on the first of each month but on another date)
Hello! I have a data frame with dates. I need to create a new "month" that starts on the 20th of each month - because I'll need to aggregate my data later by that "shifted" month. I wrote the code below and it works. However, I was wondering if there is some ready-made function in some package - that makes it easier/more elegant? Thanks a lot! # Example data:
2010 Jan 15
2
processing all files with certain extension in a directory
Hi all, I'm trying to process all files with a certain extension "*.ext" in a directory like this: > R --slave --args /my/dir < dir_plot.r where I then I want to do something like: myarg <- commandArgs() inputdir <- myarg[length(myarg)] print(inputdir) "for file with extension "*.ext in inputdir" do data = process.data(file) outfile =
2007 Sep 01
2
Comparing "transform" to "with"
Hi All, I've been successfully using the with function for analyses and the transform function for multiple transformations. Then I thought, why not use "with" for both? I ran into problems & couldn't figure them out from help files or books. So I created a simplified version of what I'm doing: rm( list=ls() ) x1<-c(1,3,3) x2<-c(3,2,1) x3<-c(2,5,2)
2009 Jan 20
5
Problem with subset() function?
Hi all, Can anyone explain why the following use of the subset() function produces a different outcome than the use of the "[" extractor? The subset() function as used in density(subset(mydf, ht >= 150.0 & wt <= 150.0, select = c(age))) appears to me from documentation to be equivalent to density(mydf[mydf$ht >= 150.0 & mydf$wt <= 150.0, "age"])
2005 Feb 03
2
Surprising Behavior of 'tapply'
Dear all, I wanted to make a two-way-table of two variables with a counting variable stored in another column of a dataframe. In version 1.9.1, the behavior is as expected as shown in the simplified example code. > sex <- rep(c("F", "M"), 5) > income <- c(rep("low", 5), rep("high", 5)) > count <- 1:10 > mydf <-
2011 Jun 09
1
Error: missing values where TRUE/FALSE needed
I'm writing a function and keep getting the following error message. myfunc <- function(lst) { lst <- list(roots = c("car insurance", "auto insurance"), roots2 = c("insurance"), prefix = c("cheap", "budget"), prefix2 = c("low cost"), suffix = c("quote", "quotes"), suffix2 = c("rate",
2005 Dec 08
3
Reshaping data
Dear all, given I have data in a data.frame which indicate the number of people in a specific year at a specific age: n <- 10 mydf <- data.frame(yr=sample(1:10, size=n, replace=FALSE), age=sample(1:12, size=n, replace=FALSE), no=sample(1:10, size=n, replace=FALSE)) Now I would like to make a matrix with (in this simple example) 10 columns (for the
2013 Feb 18
1
ggplot2 and facet_wrap help
Dear R experts, I am trying to arrange multiple plots, creating one graph for each size1 factor variable in my data frame, and each plot has the median price on the y-axis and the size2 on the x-axis grouped by clarity: library(ggplot2) df <- data.frame(price=matrix(sample(1:1000, 100, replace = TRUE), ncol = 1)) df$size1 = 1:nrow(df) df$size1 = cut(df$size1, breaks=11)
2017 Nov 22
1
assign NA to rows by test on multiple columns of a data frame
...well, I don't think this is exactly the expected result (see my post) to be noted that the columns affected should be "A" and "B" thanks for the help max ----- Messaggio originale ----- Da: "Rui Barradas" <ruipbarradas at sapo.pt> A: "Massimo Bressan" <massimo.bressan at arpa.veneto.it>, "r-help" <r-help at
2017 Nov 22
0
assign NA to rows by test on multiple columns of a data frame
Hello, Try the following. icol <- which(grepl("flag", names(mydf))) mydf[icol] <- lapply(mydf[icol], function(x){ is.na(x) <- x == 0 x }) mydf # A A_flag B B_flag #1 8 10 5 12 #2 7 NA 6 9 #3 10 1 2 NA #4 1 NA 1 5 #5 5 2 0 NA Hope this helps, Rui Barradas On 11/22/2017 10:34 AM, Massimo Bressan
2011 Aug 16
1
Utilizing column names to multiply over all columns
## Hello there, ## I have an issue where I need to use the value of column names to multiply with the individual values in a column and I have many columns to do this over. I have data like this where the column names are numbers: mydf <- data.frame(`2.72`=runif(20, 0, 125), `3.2`=runif(20, 50, 75), `3.78`=runif(20, 0, 100), yy=
2011 Jun 14
1
Invalid Regular Expression
I'm working with some data, and am trying to generate it in the following format. state city zipcode I like pizza 0 0 0 I live in Denver 0 1 0 All the fun stuff is in Alaska 1 0 0 he lives in 66062
2013 Feb 26
2
merging or joining 2 dataframes: merge, rbind.fill, etc.?
#I want to "merge" or "join" 2 dataframes (df1 & df2) into a 3rd (mydf). I want the 3rd dataframe to contain 1 row for each row in df1 & df2, and all the columns in both df1 & df2. The solution should "work" even if the 2 dataframes are identical, and even if the 2 dataframes do not have the same column names. The rbind.fill function seems to work. For
2007 Sep 02
2
NAs in indices
Hi All, I'm fiddling with an program to read a text file containing periods that SAS uses for missing values. I know that if I had the original SAS data set instead of a text file, R would handle this conversion for me. Data frames do not allow missing values in their indices but vectors do. Why is that? A search of the error message points out the problem and solution but not why they
2017 Nov 22
1
assign NA to rows by test on multiple columns of a data frame
OPS, Sorry i did not read the post carfully. Mine will not work if you have zeros on columns A and B.. But you could modify it to work for specific columns i believe. EK On Wed, Nov 22, 2017 at 8:37 AM, Ek Esawi <esawiek at gmail.com> wrote: > Hi *Massimo,* > > *Try this.* > > *a <- mydf==0mydf[a] <- NAHTHEK* > > On Wed, Nov 22, 2017 at 5:34 AM, Massimo Bressan