Displaying 20 results from an estimated 2000 matches similar to: "fill an array by rows"
2010 Jun 01
1
loop
Can any one help it will be very kind, loop statements
I have this table and some more records, I want to reshape it
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
TP53 Dis1 Dis2 Dis3 Dis4 Dis5 Dis6
DCI New1 New2 New3 New4
FDI Hi2 H3 H4
GHD I1 I3 I4 I5 I6 I7 I8
I want my new table or matrix to be some thing like this
V1 V2 V3
Tp53 Dis1 Dis2
Tp53 Dis1 Dis3
Tp53 Dis1 Dis4
Tp53 Dis1 Dis5
Tp53 Dis1 Dis6
Tp53 Dis2
2007 Oct 12
1
use 'lapply' to creat 2 new columns based on old ones in a data frame
There is a dataset 'm', which has 3 columns: 'index', 'old1' and 'old2';
I want to create 2 new columns: 'new1' and 'new2' on this condition:
if 'index'==i, then 'new1'='old1'+add[i].
'add' is a vector of numbers to be added to old columns, e.g. add=c(10,20,30
...)
Like this:
index old1 old2 new1
2011 Sep 23
4
replace multiple string
Hi
I would like to use a bash script that searches files and
subdirectories name in a directory /var/ww/html/web
for a specific string, and when it finds the search string, replaces
the string (old1) with new string (new1), and so on
old2 with new2 ....oldn with newn.
replace_string.sh
#!/bin/bash
for db in $(find /var/www/html/web -name * -exec)
do
sed -e "s/old1/new1/" \
sed
2011 Feb 18
6
sort a 3 dimensional array across third dimension ?
I'm attempting to sort a 3 dimensional array that looks like this
> x
, , 1
[,1] [,2]
[1,] 9 9
[2,] 7 9
, , 2
[,1] [,2]
[1,] 6 5
[2,] 4 6
, , 3
[,1] [,2]
[1,] 2 1
[2,] 3 2
Such that it ends up like this ....
> y
, , 1
[,1] [,2]
[1,] 2 1
[2,] 3 2
, , 2
[,1] [,2]
[1,] 6 5
[2,] 4 6
, , 3
[,1] [,2]
2008 May 15
2
How to remove autocorrelation from a time series?
Dear R users,
someone knows how to remove auto-correlation from a frequencies time series?
I've tried by differencing (lag 1) the cumulative series (in order to have only positive numbers) , but I can't remove all auto-correlation.
If it's useful I can send my db.
x <- # autocorrelated series
new1<-cumsum(x)
new2<-diff(new1,lag=1,differences = 1)
acf(new2) #
2008 Jun 10
2
convert characters into integers in a matrix
Hello,
I will appreciate any suggestion for this simple problem. I have a matrix of
characters "A", "P", "M".
I want to convert those characters to integers 0,1, 1 respectively. I am
using the following R statements:
exprs.new<-gsub("P",1,exprs)
exprs.new1 <- gsub("A",0,exprs.new)
exprs.new2 <-
2011 Mar 30
5
save ordinary numerical calculations as pdf
I'd like to save some calculation outputs as a pdf, to incorporate with others in a document. I've tried
pdf("filename")
name_of_object_to_output
dev.off()
but it doesn't seem to work, appears that this pdf function is for graphics?
Is there a way to output numerical objects to pdf?
Thanks
J
Dr. Jim Maas
University of East Anglia
2011 Feb 17
7
removing lower and upper quantiles from an arry
I'm trying to work out the simplest way to remove the upper and lower quantiles, in this case upper and lower 25% from an array. I can do it in two steps but when I try it in one, it fails. Is there something simple missing from my syntax or are there other simple elegant way to accomplish this?
Thanks
J
> i <-1:20
> i2 <- i[i<quantile(i,.75)]
> i3 <-
2011 Mar 14
7
creating character vector
Is there a way to convince R to create a character vector without using the quotes?
This works
ex1 <- c("first","second")
but when I try this it doesn't
ext <- as.character(c(first,second))
it complains. I have many variables to put into character vectors so dispensing with the quotes would be useful.
Thanks
Jim
===============================
Dr. Jim Maas
2010 Aug 24
3
multiple assignments ?
Simple one, have read and googled, still no luck!
I want to create several empty vectors all of the same length.
I would like multiple empty vectors (vec1, vec2, vec3) and want to create them all in one line.
I've tried
vec1,vec2,vec3 <- vector(length=5)
and
c(vec1,vec2,vec3) <- vector(length=5)
and several other attempts but nothing seems to work ... suggestions?
Thanks
Jim
2011 Feb 05
1
Seeking help to define method for '+'
Dear all, I am trying to define "+" method for my newly defined s4 class
which is as follows:
setClass("Me", sealed=F,representation(x1 = "numeric", x2 = "character"))
new1 <- new("Me", x1=2, x2="comment1")
new2 <- new("Me", x1=3, x2="comment1")
setMethod("+", "Me",
2009 Apr 09
2
failed when merging two dataframes, why
Hi, R-listers,
Failed, when I tried to merge df1 and df2 by "codetot" in df1 and "codetoto"
in df2. I want to know the reason and how to merge them together. Data
frames and codes I have used were listed as followed. Thanks a lot in
advance.
df1:
popcode codetot p3need
BCPy01-01 BCPy01-01-1 100.0000
BCPy01-01 BCPy01-01-2 100.0000
BCPy01-01 BCPy01-01-3 100.0000
BCPy01-02
2010 Sep 16
5
using variable from for loop in naming new variables
Simple one here ... but can't get it to work ...
for (i in 1:4){
paste("stuff",[i]),sep="") <- 3 + i
}
ls()
rm(list=ls())
I just want it to create 4 new variables called stuff1, stuff2, stuff3, stuff4 with the corresponding assignments. I realise that there are more elegant functions but this is just a model of a bigger situation.
Thanks
Jim
2010 Oct 20
2
create a list fails
I can not understand why this fails
>
> faicoutput2 <- list(stuff21 = as.numeric(faicout$coefficients[2]),
+ stuff31=as.numeric(faicout$coefficients[3]),
+ stuff41=as.numeric(faicout$coefficients[4]),
+ stuff32=(stuff21-stuff31),
+ stuff42=(stuff21-stuff41),
+
2010 Aug 31
4
pasting together 2 character arrays
If possible I would like to combine two different character arrays in combinations
Array1 <- c("height","weight","age","sex")
Array2 <- c("trt0","trt1","trt2")
I would like to combine these two character vectors to end up with such ...
Array3
"height.trt0.trt1"
"height.trt0.trt2"
2011 Feb 17
2
does range of values in array include a third value?
I'm using the range command to get the minimum and maximum values of an array as in
x <- range(array_y)
which gives me two values such as
[1] -2 9
I need to be able to test if this range of values includes a third value. For example I'd like to query
1) does the range of -2 to 9 include 3, answer TRUE
2) does the range of -2 to 9 include -6, answer FALSE?
All values could be
2010 Dec 15
3
calculating mean of list components
I get a list object from an iterative function. I'm trying to figure
out the most efficient way to calculate the mean of one element, across
all components of the overall list.
I've tried
output <- mean (listobject[[1:5]]$element)
to get the mean of "element" in the first five components?
It doesn't like the $. I'm suspect one of the "apply" functions
2010 Aug 20
2
output values from within a function
Is it possible to get R to output the value of an expression, that is being calculated within a function? I've attached a very simple example but for more complicated ones would like to be able to debug by seeing what the value of specific expressions are each time it cycles through a loop that executes the expression. I'm relatively new to this so there may be much simpler more elegant
2010 Aug 18
2
combinations
I would appreciate any suggestions on which function to use to write subsequent functions analysing combinations of treatments.
This refers to experimental trials of medical treatments. I want to write routines to analyse various comparisons (combinations)
So .... if 5 treatments are available (t01, t02, t03, t04 and t05) I want to write a general routine that works out all possible
2011 Jul 06
1
elegant way of removing NA's and selecting specific values from a data.frame
I have a data.frame "e" and would like to extract the 23rd column,
remove any NA's and then remove any values >= 30. I can do it in steps
such as this but have failed to figure out how to do it in a single line
.... any suggestions?
first <- e[,23]
second <- first[!is.na(first)]
third <- second[second<=30]
thanks a bunch
J
--
Dr. Jim Maas
University of East