similar to: pass by reference

Displaying 20 results from an estimated 7000 matches similar to: "pass by reference"

2012 Aug 13
4
if else elseif for data frames
Hi all, It seems like I cannot use normal 'if' for data frames. What would be the best way to do the following. if data$col1='high' data$col2='H' else if data$col1='Neutral' data$col2='N' else if data$col='low' data$col2='L' else #chuch a warning? Note that col2 was not an existing column and was newly assigned for this
2012 Aug 14
2
anova in unbalanced data
Hi all, Say I have the following data: a<-data.frame(col1=c(rep("a",5),rep("b",7)),col2=runif(12)) a_aov<-aov(a$col2~a$col1) summary(aov) Note that there are 5 observations for a and 7 for b, thus is unbalanced. What would be the correct way of doing anova for this set? Thanks, Sachin [[alternative HTML version deleted]]
2013 Jun 26
3
match rows of R
Hi all, What would be an efficient way to match rows of a matrix to a vector? ex: m<-matrix(1:9, nrow=3) m [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 ################################# which(m==c(2,5,8)) # I want this to return 2 ###################### Thanks, Sachin [[alternative HTML version deleted]]
2013 Sep 13
2
xtable use plus minus
I am using a similar dataset to the following: a= c("Fruits", "Adam","errorA", "steve", "errorS", "apples", 17.1,2.22, 3.2,1.1, "oranges", 3.1,2.55, 18.1,3.2 ) a_table=data.matrix(t(matrix(a,nrow=5))) I would like to plus minus every second column starting from errorA (using xtable/ hmisc) example output (ignoring
2013 May 02
3
Divide matrix columns by different numbers
Hi all, I have a feeling the most efficient way to do the following is to use apply, but I'm still wrapping my head around the function. k=matrix(1:6,nrow=3) div=1:2 Questions is how do I get R to divide the first column by 1 (div[1]) and the second column by 2 (div[2]) k/div treats k as a vector and does the following (not what I want) >k/div [,1] [,2] [1,] 1 2 [2,]
2013 Apr 18
3
Using different function (parameters) with apply
Hi All, I have the following problem (read the commented bit below): a<-matrix(1:9,nrow=3) a [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 div<-1:3 apply(a,2,function(x)x/div) ##want to divide each column by div- instead each row is divided## [,1] [,2] [,3] [1,] 1 4.0 7 [2,] 1 2.5 4 [3,] 1 2.0 3
2005 Oct 07
2
finding missing lines...
Take this as an example: > a=data.frame(col1=c(1,2,3,4,5), col2=c ("my","beloved","daughter","son","wife")) > b=data.frame(col1=c(1,2,4), col2=c("my","beloved","son")) > a col1 col2 1 1 my 2 2 beloved 3 3 daughter 4 4 son 5 5 wife > b col1 col2 1 1 my 2
2012 Aug 14
3
set working directory to current source directory
Hi all, Is there a way to get cran R to set the working directory to be wherever the source file is? Each time I work on a project on different computers I keep having to set the working directory which is getting quite annoying. Thanks, Sachin [[alternative HTML version deleted]]
2013 Jan 14
4
Grabbing Specific Words from Content (basic text mining)
Hi all, Suppose I have a data frame with mixed content (name age and address). a<-"Name: John Smith Age: 35 Address: 32, street, sub, something" b<-data.frame(a) 1. The question is I want to extract the name age and address separately from this data frame (containing potentially more people). 2. Also just incase I have to deal with it how would the syntax change if I had
2012 Aug 11
3
choosing multiple columns
Hi all, I have a data frame that has the columns OFB1, OFB2, OFB3,... OFB10. How do I select the first 8 columns efficiently without typing each and every one of them. i.e. I want something like: a<-data.frame(initial_data$OFB1-10) #i know this is wrong, what would be the correct syntax? Thanks, Sachin [[alternative HTML version deleted]]
2011 Nov 18
2
calling self written R functions
Hi All, I have written a function (say) called foo, saved in a file called foo.R. Just going by Matlab syntax I usually just change my folder path and therefore can call it at will. When it comes to R, how is the usual way of calling/loading it? because R doesnt seem to automatically find the function from a folder (which might be stupid to attempt in the first place). Thanks, Sachin
2011 Nov 28
2
efficient way to fill up matrix (and evaluate function)
Hi All, I want to do something along the lines of: for (i in 1:n){ for (j in 1:n){ A[i,j]<-myfunc(x[i], x[j]) } } The question is what would be the most efficient way of doing this. Would using functions such as sapply be more efficient that using a for loop? Note that n can be a few thousand. Thus atleast a 1000x1000 matrix. Thanks, Sachin [[alternative HTML version
2006 Apr 20
2
Count Unique Rows/Values
Hi, I have a dataset which has both numeric and character values with dupllicates. For example: 155 A 138 A 138 B 126 C 126 D 123 A 103 A 103 B 143 D 111 C 111 D 156 C How can I count the number of unqiue entries without counting duplicate entries. Also can I extract the list in a object. What I mean is Col1 unique count = 8 Unique Elements are :
2011 Dec 06
2
configuring a package for own personal needs
Hi All, There is a function in package "R2Cuba" called Cuhre that I need to use. It keeps spitting out a new-line which I really dont want it to do. So I was wondering what is the best way of configuring the package. I tried copying and pasting the code into Cuhre2 and getting rid of the newline command BUT that didn't work since it seems to have some private functions which I do
2013 Mar 08
2
Select rows from Data Frame with conditions
Hi all, I have two dataframes. The first (A) contains all the stock prices for today including today. So the first column is the stock Symbol and the second column is the stock price. The second (B) is the symbol list in the top 100 stocks. I want to pick out from dataframe A only the rows containing the symbols from B. i.e. something like: prices <- A[A[,1]==B,2] is there any
2011 Mar 16
3
making dataframes
Dear all, I have a dataframe which looks like this (dummy): date<-c("jan", "feb", "mar", "apr", "may", "june", "july", "aug","sep","oct","nov","dec") col1<-c(8.2,5.4,4.3,4.1,3.1,2.5,1.1,4.5,3.2,1.9,7.8,6.5) col2<-c(3.1,2.3,4.7,6.9,7.5,1.1,3.6,8.5,7.5,2.5,4.1,2.3)
2010 Nov 10
5
arrays of arrays
Hi All, I want to have an array/ matrix that looks this x<- 0 0 1 1 1 3 5 4 4 7 -1 8 9 10 6 I hope this makes sense. So basically if I want x[1,3] it will access 0 and similarly x[4,2], -1. Thanks in advance, Sachin p.s. sorry about the corporate notice. --- Please consider the environment before printing this email --- Allianz - Best General Insurance Company of the Year 2010*
2017 Aug 23
0
Comparing 2 dale columns
Patrick, ## Run the following script an notice the different values of the dataframe "data" in each instance. # I understand you have done something like the following: data <- data.frame(COL1 = c("6/1/14", "7/1/14"), COL2 = c("5/1/15", "5/1/15"), stringsAsFactors = FALSE) data$Date_Flag <- ifelse(data$COL2 >
2006 Mar 16
3
Did I use "step" function correctly? (Is R's step() function reliable?)
Hi all, I put up an exhaustive model to use R's "step" function: ------------------------ mygam=gam(col1 ~ 1 + col2 + col3 + col4 + col2 ^ 2 + col3 ^ 2 + col4 ^ 2 + col2 ^ 3 + col3 ^ 3 + col4 ^ 3 + s(col2, 1) + s(col3, 1) + s(col4, 1) + s(col2, 2) + s(col3, 2) + s(col4, 2) + s(col2, 3) + s(col3, 3) + s(col4, 3) + s(col2, 4) + s(col3, 4) + s(col4, 4) + s(col2, 5) + s(col3,
2018 Feb 25
2
include
HI Jim and all, I want to put one more condition. Include col2 and col3 if they are not in col1. Here is the data mydat <- read.table(textConnection("Col1 Col2 col3 K2 X1 NA Z1 K1 K2 Z2 NA NA Z3 X1 NA Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE) The desired out put would be Col1 Col2 col3 1 X1 0 0 2 K1 0 0 3 Y1 0 0 4 W1 0 0 6 K2 X1