Displaying 20 results from an estimated 5000 matches similar to: "Help with loop"
2012 Jul 11
1
sapply question
Why does this sapply code change df3 but not df1?
Thanks
df1 <- read.table(text="
cola colb colc cold cole
1 NA 5 9 NA 17
2 NA 6 NA 14 NA
3 3 NA 11 15 19
4 4 8 12 NA 20
", header=TRUE)
df2 <-df1*2
df1
df2
df3 <-sapply(names(df1),function(x) {df1[[x]]<- df2[[x]]})
df1
df3
[[alternative HTML version deleted]]
2009 Jul 12
2
Nonlinear Least Squares nls() programming help
Hi, I am trying to use the nls() function to closely approximate a vector of
values, colC and I'm running into trouble. I am not sure how if I am asking
the program to do what I think its doing, because the same minimization in
Excel's Solver does not run into problems. If anyone can tell me what is
going wrong, and why I'm getting a singular convergence(7) error, please
tell me. I
2005 Sep 09
3
how to do something like " subset(mat, ("col1">4 & "col2">4)) "
Dear all,
I have a problem with the "subset()" function. I spent all day yesterday
with a collegue to solve it and we did not find a satisfying solution (even
in the archived mails), so I ask for your help.
Let's say (for a simple example) a matrix mat:
R> mat
cola colb colc
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
My goal is to select the lines of the matrix on the basis of the
2013 Apr 30
2
R Function to extract columnNames
Hi,
May be this helps:
funcName<- function(df1, x){
?whatCol=df1[[x]]
?print("Got it")
?print(whatCol)
?}
?
funcName(df,"ColA")
#[1] "Got it"
#[1] 1 2 3 4 5
? funcName(df,"ColB")
#[1] "Got it"
#[1] A B C D E
#Levels: A B C D E
A.K.
>I am trying to extract the 2nd column from a dataframe using a function
called funcName. Note this is an
2011 Jun 10
2
Sorting Data Frame Without Loop
Hello all!
I am currently trying to sort a data frame in a particular way, but I am having some difficulties with this. Specifically I want to sort the below dataset in such a way that there is only one line per ProteinID and if there are multiple GeneID or GeneName entries for a single proteinID, that they be concatenated with a comma separating them. The way I have done it earlier worked fine
2010 Dec 09
2
Reshape Columns
Hello,
I have a general formatting question. I have two columns of data:
ColA <- c("m", "m", "m", "m")
ColB<- c("d","d","d","d")
And I would like to reorder them into a new column that looks like this:
ColC<-
2012 Oct 04
4
Subsetting a group of data
Hi,
I am making my way down the learning curve of R, and find it a great
language with so many helpful users!
Below is an example of what I'm trying to do, but can't quite figure out the
right path to go down.
Here's what I have:
Main is a time series of data with columns Cola and Colb
Cola Colb
1 1 1
2 1
2008 Jun 27
2
change values in data frames
Hello every body,
I am quite a new user of R so I beg your pardon for this naive question and
the lake of syntax with wich I ask it:
I have a data frames like this:
cola colb
1 c
1 i
1 i
1 c
2 i
2 c
2 c
2 i
2 i
...
10000
I would like ,for each level of cola and for x in colb:
-if colb[x]=="i" and colb[x-1] does not exist (first row in dataframes),
then replace colb[x] by
2011 Aug 03
2
Error message for MCC
Greetings all,
I am getting an error message that is stifling me.
Any ideas?
> ## Define Directories ##
> load_from <- "/home/mcc/Dropbox/abrodsky/kegg_combine_data/"
> save_to <- "/home/mcc/Dropbox/abrodsky/ttest_results/"
>
> ###############################
> ## Define Columns To Compare ##
> compareA <- "log_b_rich"
> compareB
2011 Aug 05
2
Which is more efficient?
Greetings all,
I am curious to know if either of these two sets of code is more efficient?
Example1:
## t-test ##
colA <- temp [ , j ]
colB <- temp [ , k ]
ttr <- t.test ( colA, colB, var.equal=TRUE)
tt_pvalue [ i ] <- ttr$p.value
or
Example2:
tt_pvalue [ i ] <- t.test ( temp[ , j ], temp[ , k ], var.equal=TRUE)
-------------
I have three loops, i, j, k.
One to test the all of
2012 Jul 14
3
Can't understand syntax
OK, I need help!!
I've been searching, but I don't understand the logic of some this
dataframe addressing syntax.
What is this type of code called?
test [["v3"]] [is.na(test[["v2"]])] <-10 #choose column v3 where column v2
is == 4 and replace with 10
and where is it documented?
The code below works for what I want to do (find the non-missing value in a
row),
2005 Aug 22
3
read a table ignoring specific rows ?
Dear R users,
First of all sorry for this question, surely quite naive.
(I searched on the R site but was unable to find by myself).
I have a table, called infile :
1 2 3
4 5 6
7 8 9
I would like to read it and ignore the rows with 1st element > 3
I do it now with a for loop, and it's ok,
but I was expecting something simpler, like :
intable = read.table(infile);
newtable =
2015 Feb 24
2
intercalar elementos de vectores
Gracias, Carlos.
Habia pensado en algo similar usando sapply():
sapply(seq(1, ncol(vtmp), by = 2), function(i) c(rbind(as.character(vtmp[,
i]), as.character(vtmp[, i+1]))))
Dependiendo de la dimension de los datos, quizas mapply() sea mas eficiente
que sapply().
Saludos cordiales,
Jorge.-
2015-02-25 1:01 GMT+11:00 Carlos Ortega <cof en qualityexcellence.es>:
> Hola,
>
> Este
2006 Apr 12
0
New class: data.table
Hi,
Following previous discussion on this list
(http://tolstoy.newcastle.edu.au/R/devel/05/12/3439.html) I have created a
package as suggested, and uploaded it to CRAN incoming : data.table.tar.gz.
** Your comments and feedback will be very much appreciated. **
>From help(data.table) :
This class really does very little. The only reason for its existence is
that the white book specifies
2011 Aug 18
2
Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?
Dear expeRts,
What is the best approach to create a third data frame from two given ones, when
the new/third data frame has last column computed from the last columns of the two given
data frames?
## Okay, sounds complicated, so here is an example. Assume we have the two data frames:
df1 <- data.frame(Year=rep(2001:2010, each=2), Group=c("Group 1","Group 2"), Value=1:20)
2013 Feb 26
2
merging or joining 2 dataframes: merge, rbind.fill, etc.?
#I want to "merge" or "join" 2 dataframes (df1 & df2) into a 3rd
(mydf). I want the 3rd dataframe to contain 1 row for each row in df1
& df2, and all the columns in both df1 & df2. The solution should
"work" even if the 2 dataframes are identical, and even if the 2
dataframes do not have the same column names. The rbind.fill function
seems to work. For
2009 Jan 21
3
merging several dataframes from a list
Hi there,
I have a list of dataframes (generated by reading multiple files) and all
dataframes are comparable in dimension and column names. They also have a
common column, which, I'd like to use for merging. To give a simple example of
what I have:
df1 <- data.frame(c(LETTERS[1:5]), c(2,6,3,1,9))
names(df1) <- c("pos", "data")
df3 <- df2 <- df1
df2$data
2013 Jan 02
2
rbind: inconsistent behaviour with empty data frames?
The rbind on empty and nonempty data frames behaves inconsistently. I am
not sure if by design.
In the first example, first row is deleted, which may or may not be on
purpose:
df1 <- data.frame()
df2 <- data.frame(foo=c(1, 2), bar=c("a", "b"))
rbind(df1, df2)
foo bar
2 2 b
Now if we continue:
df1 <- data.frame(matrix(0, 0, 2))
names(df1) <- names(df2)
2015 Feb 24
2
intercalar elementos de vectores
Excelente! Ahora corre muy rápido. No conocía ese método, creo que me va a
resultar muy útil.
Muchas gracias y saludos.
Fernando Macedo
El 24/02/15 a las 10:51, Jorge I Velez escribió:
Fernando,
Podrias intentar
R> a <- rep('a', 5)
R> b <- rep('b', 5)
R> a
[1] "a" "a" "a" "a" "a"
R> b
[1] "b"
2017 Jul 13
2
about plotting a special case
Thanks, Jim. The code works, but I don't understand why you use q1090 <-
quantile(DF1$B, probs=c()), rather than DF1$A? Also, how to add a legend
for both points DF1 and DF2?
On Wed, Jul 12, 2017 at 8:25 PM, Jim Lemon <drjimlemon at gmail.com> wrote:
> Hi lily,
> Here is the first plot:
>
> plot(DF1$A,DF1$B,pch=19,col="red")
> meanA<-mean(DF1$A)
>