similar to: apply for each value

Displaying 20 results from an estimated 20000 matches similar to: "apply for each value"

2011 Aug 05
2
[?]apply functions or for loop
Hello, First time posting to this mail list. I'd like to use R in the most efficient way. I'm accomplishing what I want, but feel there is a more R'ish way to do it. Just learning R. *My goal: get ranks of value across rows with row names and column names intact.* I'm guessing one of the [?]apply functions will do what I need, but I couldn't sort out which one (after a lot
2011 Sep 02
2
previous monday date
Hello, I'm attempting to return the date (in form '%Y-%m-%d') of the Monday previous to the current date. For example: since it is 2011-09-02 today, I would expect 2011-08-29 to be the return value. I found the following in: http://www.mail-archive.com/r-help@r-project.org/msg144184.html Start quote from link: prevmonday <- function(x) 7 * floor(as.numeric(x-1+4) / 7) +
2011 Oct 11
1
high and lowest with names
Hello, I'm looking to get the values, row names and column names of the largest and smallest values in a matrix. Example (except is does not include the names): > x <- swiss$Education[1:25] > dat = matrix(x,5,5) > colnames(dat) = c('a','b','c','d','c') > rownames(dat) = c('z','y','x','w','v') >
2011 Sep 27
3
remove NaN from element in a vector in a list
Hello, What is the best way to turn a matrix into a list removing NaN's? I'm new to R... Start: > mt = matrix(c(1,4,NaN,5,3,6),2,3) > mt [,1] [,2] [,3] [1,] 1 NaN 3 [2,] 4 5 6 Desired result: > lst [[1]] [1] 1 3 [[2]] [1] 4 5 6 Thanks! Ben [[alternative HTML version deleted]]
2011 Nov 23
2
zeros to NA's - faster
Hello, Is there a faster way to do this? Basically, I'd like to NA all values in all_data if there are no 1's in the same column of the other matrix, iu. Put another way, I want to replace values in the all_data columns if values in the same column in iu are all 0. This is pretty slow for me, but works: all_data = matrix(c(1:9),3,3) colnames(all_data) =
2008 May 09
2
which.max2()
Hello, which.max() only returns one index value, the one for the maximum value. If I want the two index values for the two largest values, is this a decent solution, or is there a nicer/better R'ish way? max2 <-function(v) { m=which.max(v) v[m] = -v[m] m2=which.max(v) result=c(m, m2) result } Seems to work ok. Thanks, Esmail
2011 Oct 12
1
Tinn-R change editor background color
Hello, Does anyone know how to change the Tinn-R editor background color? White is rough on the eyes... Thanks, Ben [[alternative HTML version deleted]]
2011 Aug 23
1
R.oo modify an object inside another classes method
Can someone show me how to modify one (R.oo) class's object inside another (R.oo) class's method? Is that possible with the R.oo package? A quick example or reference to an example would be outstanding... Thanks, Ben [[alternative HTML version deleted]]
2011 Aug 29
1
character vector to text with returns
Hello, Does anyone know how to convert this: > msg [1] "a" [2] "b" [3] "c" To: > msg "a b c" In other words, I need to convert a character vector to a single string with carriage returns for each row. Functionally, I'm attempting to send an email of a character vector in a way that is readable in the email body. I can only input one
2011 Sep 10
1
DBS to R
Hello, I have a bunch of data files all with "dbs" file extensions. They are generated via a SQL query from another program and source. Does anyone know (or have ideas) how to get the data from a dbs file type into R (or into some other format that can imported to R)? I've searched online for 4 hours now... Thanks! Ben [[alternative HTML version deleted]]
2011 Oct 06
1
counts in quantiles in and from a matrix
Hello, I'm trying to get the count of values in each row that are above and below quantile thresholds. Thanks! Example: > x = matrix(1:30,5,6) > x [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 6 11 16 21 26 [2,] 2 7 12 17 22 27 [3,] 3 8 13 18 23 28 [4,] 4 9 14 19 24 29 [5,] 5 10 15 20 25 30 > qtl = t(apply(x, 1,
2011 Sep 22
1
R.oo: do work on data member at construction
Hello, I'd like to 'do work' on data members upon construction (i.e. without implementing it in a get method). Is this the best way to create data member 'z' upon construction? I'm thinking if .z=paste(x,y) below gets more complex I'll run into issues. setConstructorS3("MyClass", function(x=NA,y=NA,...) { this <- extend(Object(), "MyClass",
2011 Aug 08
1
R.oo error upon construction
Hello, Using the R.oo package, how do I throw an error if a field is not present when the user of the class creates the object? Using the example in the R.oo package: setConstructorS3("Person", function(name, age) { if (missing(name)) name <- NA; if (missing(age)) age <- NA; extend(Object(), "Person", .name=name, .age=age ) }) [rest of class methods
2005 Jun 04
3
How to change the value of a class slot
I defined an S4 class with a slot i. Then I wrote a regular function that attempted to increment i. This didn't work, apparently because of the general rule that a function can't change the values of its arguments outside the function. I gather there are ways around it, but the Green book admonishes "cheating on the S evaluation model is to be avoided" (p. 190). Thinking that
2013 Mar 21
4
easy way of paste
Hello, Is there a better way to use paste such as: a = paste(colnames(list.indep)[1],colnames(list.indep)[2],colnames(list.indep)[3],colnames(list.indep)[4],colnames(list.indep)[5],sep="+") > a [1] "aa+dummy1+dummy2+bb+cc" I tried a = paste(colnames(list.indep)[1:5],sep="+") > a [1] "aa" "dummy1" "dummy2"
2006 Jun 09
3
sqlSave() and rownames=TRUE makes my Rgui crash
Hello, I created a table in MySQL with this command CREATE TABLE example (pk INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(pk), id VARCHAR(30),col1 VARCHAR(30),col2 VARCHAR(30)) ### In R, I can connect to this table: library(DBI) library(RODBC) chan <- odbcConnect("MySQL51", uid="root", pwd="xxx") first <- sqlQuery(chan, "select * from example")
2011 Sep 14
1
rJython matrix message
Hello, I've posted something similar under a different subject and never received a solution. Trying again with (hopefully) a better description. Objective: Send a matrix of string data in an email message. The message must have authentication and be sent via an R script. I'm almost there! Here is where I am at: I collect long error message lines in 'errs', which is a matrix.
2011 Aug 15
1
2 matrix scatter x [a lot]
Hello, I'm pretty new to R. Basically, how do I speed up the for loop below. Or better yet, get rid of the for loop all together. objective: plot two data sets column against column by index. These data sets have alot NA's. Some columns are all NA's. I need the plots to overlay. I don't like the plots in matplot(). Needs to be much faster than the code below... #simple sample
2011 Aug 26
1
R.oo data members / inheritance
If someone is able, can you tell me if there is a better way to do this? More specifically, do I have to rewrite all of the data members stuff and extend stuff of parent class in the child class? See below. Thanks in advance! Example 1: setConstructorS3("ClassA", function(A,x) { if(missing(A))A=15; if(missing(x))x=NA; extend(Object(), "ClassA", .size = A, .x=x
2005 Oct 29
1
how to get colnames of a dataframe within a function called by 'apply'
Hello alltogether, how is it possible to assign the colnames of a data.frame to a function called by apply, e.g. for labeling a plot? Example: I want to plot several qqnorm-plots side by side and there should be a maintitle for each qqnorm-plot which is identical to the respective colname. I checked, but the column which is processed by the function called by apply does not contain a colname