Displaying 20 results from an estimated 6000 matches similar to: ".net and R"
2010 Dec 03
3
colname refered by a variable
Hello,
I tried to use a variable to refer colname, but I got error, could anyone give me advice?
>df=data.frame(cbind(AB=1:3,AC=3:5))
> df$AC
[1] 3 4 5
> df$paste("A","C",sep="")
Error: attempt to apply non-function
thanks
Jian
[[alternative HTML version deleted]]
2008 Aug 31
3
remove low frequent rows
Hi,
I have a matrix.
>a<-cbind(c("a","b","a"),c(4,3,6))
[,1] [,2]
[1,] "a" "4"
[2,] "b" "3"
[3,] "a" "6"
I want to remove rows in matrix a whose first column has frequency less than 2.
in about example matrix a becomes
[,1] [,2]
[1,] "a" "4"
[2,] "a"
2010 May 20
5
sort a data.frame
Hello,
I have a dataframe:
dd <- data.frame(b = c("chr2", "chr1", "chr15", "chr13"),
x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9),
z = c(1, 1, 1, 2))
>dd
b x y z
1 chr2 A 8 1
2 chr1 D 3 1
3 chr15 A 9 1
4 chr13 C 9 2
Now I want to sort them according column "b", but only its
2010 Jun 14
2
list matching
Hello,
I could not find a clear solution for the follow question. please allow me to ask. thanks
mynames=cbind(c('a','b'),c(11,22))
lst=list(a=c(1,2), b=5)
now I try to combine mynames and lst:
a 1 11
a 2 11
b 5 22
thanks
jian
[[alternative HTML version deleted]]
2008 Aug 30
4
remove levels from a factor
Hi,
how to remove levels that have less than a specific number such as 2. i.e..
> f<-as.factor(c("a","b","a"))
> f
[1] a b a
Levels: a b
I want to remove level b because level b has less than 2.
> f
[1] a a
Levels: a
[[alternative HTML version deleted]]
2010 May 12
3
intersect
Hi there,
how can I test every element in a vector whether appears in another vector?
such as
a<-c("aa", "bb", "ff", "cc")
b <-c("oo","jj","bb","cc")
somefunction(a,b) gives [False, True, False, True]
thanks
yuan jian
[[alternative HTML version deleted]]
2010 Sep 11
5
for loop
Hello,
I have a simple question: I want to list numbers 1:k, but if k <1, I hope nothing listed.
how should we do?
k=2
for (i in 1:k) print(i)
[1] 1 # <-correct
[1] 2
k=0
for (i in 1:k) print(i)
[1] 1 #<---- wrong
[1] 0
thanks
jian
[[alternative HTML version deleted]]
2010 Jun 23
4
list operation
Hi,
it seems a simple problem, but I can not find a clear way.
I have a list:
lst=list(m=c('a','b','c'),n=c('c','a'),l=c('a','bc'))
> lst
$m
[1] "a" "b" "c"
$n
[1] "c" "a"
$l
[1] "a" "bc"
how can I get list elements that include a given subset? for example, for given
2010 Jun 02
3
charactor matrix convert to numeric matrix
Hello R experts,
can you tell me a simple way to convert a charactor matrix to numeric matrix?
if I use as.numeric, the matrix is converted to a vector.
a<-cbind(c("23","54","65"),c("1","2","3"))
a
[,1] [,2]
[1,] "23" "1"
[2,] "54" "2"
[3,] "65" "3"
as.numeric(a)
2010 May 21
3
vaiable in lm
Hi,
if I know the colnames x and y in the following example, I can easily to do lm.
tmp <- data.frame(x=c(1,1.2),y=c(1,2))
lm(y ~ x, data=tmp)
when the colnames are variable, what should I do? for example
colnames(tmp)[1] <- paste("aa",1,sep="_")
lm(y ~ paste("aa",1,sep="_"), data = tmp)
it gives me error.
[[alternative HTML version
2010 Sep 22
3
merge verctor and matrix
hi,
can anyone tell me how to merge a vector and a matrix?
> v=c(1,4,2)
> names(v)=c("e","r","t")
> m=matrix(c("r","t","r","s","e",5,6,7,8,9),nr=5)
> colnames(m)=c("c1","c2")
I want to do like
merge(v, m, by.x="names",by.y="c1")
I got error
Error in fix.by(by.x, x) :
2010 May 13
1
merge for data.frame and matrix
Hello,
how to merge a data.frame and a matrix by one column in the data.frame and rownames of the matrix?
df <- data.frame(col1=c("kk","yy","kk"),col2=c(6,4,3))
> df
col1 col2
1 kk 6
2 yy 4
3 kk 3
m<-matrix(c(3,8,56,9), nrow=2, dimnames = list(c("aa","kk"),c("col1","col2")))
> m
col1 col2
aa
2010 Apr 29
2
by funtion
Hello,
I have a data.frame:
name col1 col2 col3 col4
AA 23 54 0.999 0.78
BB 123 5 1 0.99
AA 203 98 0.79 0.99
I want to get mean value data.frame in terms of name:
name col1 col2 col3 col4
AA 113.0000 76.0000 0.8945 0.8850
BB 123.00 5.00 1.00 0.99
I tried to use by function:
>aa<-by(test[,2:5], feature, mean)
2010 May 11
1
create a data.frame for aov
Hi R-experts,
I try to find a way to transfer a matrix to a data.frame that is used as input of aov.
can you give me advice for that?
>mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE, dimnames = list(c("row1", "row2"), c("Col1", "Col2", "Col3")))
>mdat
Col1 Col2 Col3
row1 1 2 3
row2 11 12 13
===>
2010 Jun 07
1
average two sets of columns
Hi R experts.
how can I average two sets of columns?
dd <- data.frame(b = c("chr2", "chr1", "chrY", "chr13", "chrX"),
w=11:15, x = 1:5, y = c(8, 3, 9, 9,7),
z = c(1, 1, 1, 2, 8))
expected result for mean(w,x) and mean(y,z) is
1 chr2 6 4.5
2 chr1 7 2
3 chrY 8 5
4 chr13 9 5.5
5 chrX 10 7.5
Yu
[[alternative
2010 May 10
1
how to get p-value from ave
Hi there,
I checked google for aov. usually one uses summary to see whether the p-value is small.
but I want to put aov in my script. how can I get the p-value, (0.1115, 0.6665, 0.6665 in the following example)?
thanks
YU
> datafilename="http://personality-project.org/r/datasets/R.appendix2.data"
> data.example2=read.table(datafilename,header=T)
> aov.ex2 =
2008 Aug 31
4
give all combinations
Hello,
is there a simple way to give all combinations for a given vector:
v<-c("a","b","c")
combination(v,v) becomes
"aa","ab","ac","bb","bc","cc'
combination(v,v,v) becomes
"aaa","aab","aac","abb",......
[[alternative HTML version deleted]]
2011 Jan 12
2
plot: skip a range of axis
Hi,
I am using plot to show scatter points in 2_D.
in my data, there is no data between -1 and +1 in x-axis.
I want to skip this region, i.e. x axis becomes [-Inf:-1, 1:Inf].
can any one tell me how to do?
YU
[[alternative HTML version deleted]]
2008 Apr 14
4
&& and ||
Hello there,
I got a small problem about logical calculation:
we can get a sequene from a+b as below:
> a<-c(1,2)
> b<-c(3,4)
> a+b
[1] 4 6
but when the sequences are logical. (I want to get (True,False) && (True, True) ==> (True, False), but when I do as below.
> e<-c(T,T)
> f<-c(F,T)
> e
[1] TRUE TRUE
> f
[1] FALSE TRUE
>
2010 Jul 22
1
class
Hello,
### I created two classes "A" and "B". "A" is the superclass of "B".
setClass("A", representation(s1="numeric"),prototype=prototype(s1=8))
setClass("B",contains="A",representation(s2="character"),prototype=list(s2="hi"))
myA=new("A")
myB=new("B")
#### I created