Displaying 20 results from an estimated 3000 matches similar to: "colname refered by a variable"
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 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]]
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
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 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 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 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 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 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 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 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
2008 Feb 23
2
.net and R
Hi,
is it possible to call R functions from visual studio .net such as c#?
---------------------------------
[[alternative HTML version deleted]]
2010 Sep 17
7
removing specific rows from array
I'm attempting to create an array of treatment comparisons for modelling data generation. This involves comparison of one treatment (c2) with another (c3), relative to a common comparator (c1).
Attached code gives me the correct array but need to remove duplicates. Duplicates relate only to c2 and c3
such that I need to remove
r3 because c2 and c3 are same as r1 with c2 and c3 swapped
r5
2011 Mar 17
3
Flexible rbind
Dear All,
I am trying to create a empty structure that I want to fill gradually
through the code.
I want to use something like rbind to create the basic structure first.
I am looking for a possibility to do an rbind where the columns names
dont match fully (but the missing columns can be defaulted to either
zero or n/a) (my actual data has a lot of columns).
Please see the data frames below
I
2010 Oct 14
5
Replacing N.A values in a data frame
Hello, I have a data frame as below ... in cases where I have N.A. I want
to use an average of the past date and next date .. any help?
13/10/2010 A 23
13/10/2010 B 12
13/10/2010 C 124
14/10/2010 A 43
14/10/2010 B 54
14/10/2010 C 65
15/10/2010 A 43
15/10/2010 B N.A.
15/10/2010 C 65
----------------------------------------------------------------------------
--------------------------
Thanks
2010 Nov 03
4
Drawing circles on a chart
Dear Group,
I have the following data matrix which is a timeseries.
> dput(tData)
structure(list(A = c(0.2, 0.13, 0.05, 0.1, 0.02, 0.18, 0.09,
0.06, 0.13), B = c(0.15, 0.06, 0.09, 0.02, 0.03, 0.12, 0.01,
0.15, 0.06), C = c(-0.1, 0, -0.07, -0.06, -0.05, -0.05, -0.06,
-0.08, -0.07), D = c(-0.15, -0.05, -0.1, -0.03, -0.13, -0.04,
-0.1, -0.04, -0.15), E = c(-0.17, -0.16, -0.08, -0.07, -0.09,
2010 Nov 09
3
Row-wise recurive function call
Dear Group,
I have a following dataset:
> a
A B C D
1 22 3 31 40
2 26 31 36 32
3 3 7 49 16
4 24 40 27 26
5 20 45 47 0
6 34 43 11 18
7 48 48 24 2
8 3 16 39 48
9 20 49 7 21
10 17 36 47 10
> dput(a)
structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L,
17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L),
C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L,
2010 Oct 22
2
If Statement with more than one condition
I'm unable to find the OR operator like other language .. any suggestions?
I want to do If (condition1 OR condition 2){ do something }
Thanks for answering this elementary question.
[[alternative HTML version deleted]]
2010 Oct 27
5
Best IDE for R
Dear R-Group,
I am looking for suggestions for the "best" IDE for R. Best is obviously
subjective but I need just the basic features that should function well (and
I looked through the threads already).
- Proper integration with R 2.11.1
- Good key shortcuts ... similar to the R Gui
- Manageability of Projects, etc.
- Neat formatting features
I tried Revolution R but it seems huge in
2010 Dec 03
2
data.table query
Hello Group,
I need a modification in the data.table example to get my intended
result shown below ... is there a more simple way!
dt <- data.table(A = rep(1:3, each=4), B = rep(1:4, each=3), C = rep(1:2, 6))
dt[, transform(.SD,D=mean(A)), by="B"]
The result I want is below ... which is probably long winded!
data.table(unique(as.data.frame(dt[, transform(.SD,D=mean(A)),