similar to: Conditional statement used in sapply()

Displaying 20 results from an estimated 70000 matches similar to: "Conditional statement used in sapply()"

2008 Aug 20
2
Line of best
Hi, I have a scatter plot, with an equation that best fits the scatter plot expressed as: 1/x^.6. I know for normal linear regression lines you can use the abline() command; however, since my best fit line is not linear, how can I draw my line on the scatter plot in a similar fashion to abline(). Thanks for everyone's help again. I appreciate this board's advice. Mark
2008 Aug 19
2
conditional with and operators
Hi, I have a problem in which I am parsing data from a list. I am simply trying to return data that has several conditions being true. Here is my syntax below: d<-sapply(res,function(.df){(.df$TimesVisited[.df$Tick>912 && .df$Id>0])}) #res is the list, and I am trying to return a result that has two true conditions (that is the variable Tick should be greate than 912 and Id
2007 Dec 19
3
Aggregating by a grouping
Suppose I have: Book Value A 10 B 11 C 9 D 8 A 12 C 4 D 5 B 7 I want to summarize above not by Book but by groupings of Books as in (below) I have a list ... basic_map <- list(c("A",B"),c("C,D")) Big_names <- c("A1", "A2") Names(basic_map) <- big_names So I want to get : A1 40 A2 26 How do I use tapply AND the list to get my
2007 Dec 26
2
Rbind-ing a list into one item
Hi, I am doing the following: 1. I have a list of files.. Files1=list.files("some directory",pattern="some pattern") 2. I define a list as res=vector("list", length(files1)) 3. I read all the files into this list: res=lapply(files1, read.csv) I now want to rowbind all the items in the list into one big mass (all files have same number of columns). I tried
2009 Mar 20
2
functions within a list
Hi, I am trying to perform various functions on a list with a number of elements. For example. I would like to take the mean of different variable values in the entire list. As an example, say I have a list with 1000 elements and variables called Id and Tick. What I would like to do is take the mean of a variable called X for each Tick in the data element. So, there can be say 1 to 600 tick
2008 Jan 08
1
Error with rbind and zoo
Hi all: I have a directory of files as in -------------> bunchafiles <- list.files(path="/data/2.3/2006", pattern="returns", full.names=T,recursive=T) .... Each file is a bunch of returns for a particular date (unique). There are like 252 files or so. With a custom function myread (below), I define a vector ----- res <-
2011 May 16
2
conditional rowsums in sapply
Hi all I have a data frame with duplicate columns and i want to remove duplicates by adding rows in each group of duplicates, but have lots of NA's. Data: dfrm <- data.frame(a = 1:4, b= 1:4, cc= 1:4, dd=1:10, ee=1:4) names(dfrm) <- c("a", "a", "b", "b", "b") dfrm[3,2:3]<-NA dfrm a a b b b 1 1 1 1 1 1 2 2 2 2 2 2 3
2008 Jan 10
5
Extracting last time value
I have a dataframe as follows: Date time value 20110620 11:18:00 7 20110620 11:39:00 9 20110621 11:41:00 8 20110621 11:40:00 6 20110622 14:05:00 8 20110622 14:06:00 6 For every date, I want to extract the row that has the greatest time. Therefore, ending up like: 20110620 11:39:00 9 20110621 11:41:00 8 20110622 14:07:00 6 I am using for loops (for every date, find largest time value) to do
2008 Aug 12
2
Parsing array data
Hi, I read in csv files with the following code: res <- vector(mode="list",length=3) for(i in 1: length(res)) res[[i]]<-read.csv(file=paste("/Users/markaltaweel/Desktop/Output/HydroDataOutput",i,".csv",sep=""),header=T,sep=",") This allows me to load the data into an array of length 3, with the res array containing my data from the csv
2008 Dec 29
4
Merge or combine data frames with missing columns
Hi R-experts, suppose I have a list with containing data frame elements: [[1]] (Intercept) y1 y2 y3 y4 -6.64 0.761 0.383 0.775 0.163 [[2]] (Intercept) y2 y3 -3.858 0.854 0.834 Now I want to put them into ONE dataframe like this: (Intercept) y1
2009 Mar 26
4
Reading in files with variable parts to names
Dear all, I'm trying to read in a whole directory of files which have two variable parts to the file name: year and month. E.g. comp198604.asc represents April of 1986 - 'comp' is fixed in each case. Years range between 1986 to 1995 and months are between 1 and 12. Just to be clear, there are 12 files associated with each year: e.g. comp198601, comp198602, ... comp198612 through to
2009 Jan 08
1
Convert to as.Date
Hi, I have an vector object that looks like DA <- c("1991q1", "1993q2") (first quarter of 1991 etc) and I want to convert it into a date object using as.Date(). I did this for montly data but am stumped when it comes to dealing with quarterly data and as.Date. Would anyone be able to help? Would be very grateful for any advice, sorry for being such an R-newbie!
2009 Mar 25
4
Manual sort in a for loop
Dear all, I am trying to manually re-sort rows in a number of tables. The rows aren't sorted on any particular values but are simply ordered by user choice (as shown by the row numbers in the code). I have been able to carry out each re-arrangement without the use of the 'for' loop, but cannot seem to successfully execute the statements when incorporated into the loop. The code I have
2008 Aug 06
4
Union of columns of two matrices
I was posed the following problem/teaser: given two matrices, come up with an "elegant" (=fast & short) function that returns a matrix with all and only the non-duplicated columns of both matrices; the column order does not matter. In essence, a matrix equivalent of union(x,y), where x and y are vectors. I could not come with anything nice. Any ideas? Giuseppe -- Giuseppe A.
2009 Mar 25
2
Plot inside For loop
Hi I am plotting a set of data inside a for loop. Is it possible to use plot in for loop without redrawing the whole plot? Am using par(new=TRUE) but that draws on top of the previous plot. Couldn't find any threads about the topic. Thanks Mohan --
2009 Feb 25
1
How to get JRI to work from my NetBeans
Hi, I need your help. I have downloaded a precompiled JRI as part of rJava. I have included rJava as part of my R package libraries. Now I need to be able to work with some R functions from my Java apps. I'm using NetBeans on Windows. I have followed some instructions from http://www.rforge.net/JRI/ but i keep on getting errors when compiling my Java app as follows: run: Cannot find JRI
2010 Feb 01
2
Merging vector data into one file
Hi, I had another question. If you had say a vector (e.g., called data) with 235 elements and each element looked like the following data[[1]] Column A-B Column Z-S Column A-S.... 1 2 5 ....... data[[2]] Column Z-B Column A-S Column A-B.... 2 1 3 ....... Anyway, each element consists of one row
2009 Apr 02
4
Deleting rows based on identity variable
I have created this data frame to help illustrate my problem. id<-c(rep(1,5),rep(2,5),rep(3,5),rep(4,5),rep(5,5)) x<-rep((seq(1:5)),5) y<-c(0, 0.1, 0.5, 0.4, 0.2, 0, 0.1, 0.5, 0.4, 0.12, 0, 0.1, 0.5, 0.55, 0.2, 0, 0.1, 0.5, 0.3, 0.2, 0, 0.1, 0.6, 0.4, 0.1) d1<-cbind(id,x,y) I would like to delete all rows where id=4, however, when I tried the command  d2=d1[-c(id==4),] and looked
2009 Feb 25
2
reshape from wide to long
Hi,I would like to reshape the following "wide" data set to "long" form. I would appreciate help with the correct code for "reshape". I tried a few unsuccessfully. Thanks. Chetty __________________________________________________ dat.1 Grp X0 X3 X6 X12 X25 X501 C 0.5326517 0.6930942 0.9403883 1.157571
2002 Jun 26
22
FW: samba woes
All, I have been working on a component that is included with samba called SMBSH. The binary allows you to automount your NT shares by accessing your profile . I have been working on this for the last few days and have been unsuccesful at getting it work. Now I am not much of a programmer, but I did my best to try and troubleshoot this. However it just does not want to work in Linux. I