Displaying 20 results from an estimated 10000 matches similar to: "assigning multiple outputs"
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]]
2012 Aug 14
4
pass by reference
Hi all,
I want to do the following:
data<-data.frame(col1=c(1,2,3,4,5))
getcol2<-function(data){
data$col2[data$col1<=2]="L"
}
getcol2(data)
Unfortunately in the above col2 does not appear in the final data. So how
would you pass this by reference such that you would get it back?
Thanks,
Sachin
[[alternative HTML version deleted]]
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
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
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
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,]
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
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
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]]
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]]
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
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
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*
2011 Nov 17
1
Vectorizing for weighted distance
Hi All,
I am trying to convert the following piece of matlab code to R:
XX1 = sum(w(:,ones(1,N1)).*X1.*X1,1); #square the elements of X1,
weight it and repeat this vector N1 times
XX2 = sum(w(:,ones(1,N2)).*X2.*X2,1); #square the elements of X2,
weigh and repeat this vector N2 times
X1X2 = (w(:,ones(1,N1)).*X1)'*X2; #get the weighted
'covariance'
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]]
2012 Aug 14
1
twitteR location?
Hi all,
Is it possible to get the latitude and longitude of the location of a
tweet? If I do
tweets<- searchTwitter("#obama", n=200) #get tweets
df <- twListToDF(tweets) #converts to data frame
for ease of viewing
it does not seem to be getting the location of where that tweet was posted.
>From what I read from the twitter API this is possible?
2012 Oct 03
1
Get Cran R to use system proxy settings
Hi all,
I am using Ubuntu and I am having quite a bit of difficulty trying to
get R to use the system proxy settings. Any suggestions?
Thanks,
Sachin
2013 Mar 08
1
getting covariance ignoring NaN missing values
Hi all,
I have a matrix that has many NaN values. As soon as one of the columns has
a missing (NaN) value the covariance estimation gets thrown off.
Is there a robust way to do this?
Thanks,
Sachin
a=array(rnorm(9),dim=c(3,3))> a [,1] [,2] [,3]
[1,] -0.79418236 0.7813952 0.855881
[2,] -1.65347906 -1.9462446 -0.376325
[3,] -0.03144987 0.6756862 -1.879801>
2013 Mar 21
1
installation of package had non-zero exit status
Hi all,
I am trying to install this NBPSeq package, but I'm now getting the
error shown below with ANY package that I try to install.
installation of package ‘NBPSeq’ had non-zero exit status
This started happening ever since I tried to install a package that I
downloaded from a personal website (for some reason only worked on my
windows partition). I'm using Ubuntu.
Any thoughts?