Steven from iPhone
> On Feb 19, 2024, at 4:56 PM, Steven Yen wrote:
>
> Thanks to all. Glad there are many options.
>
> Steven from iPhone
>
>>> On Feb 19, 2024, at 1:55 PM, Rui Barradas wrote:
>>>
>> Às 03:27 de 19/02/2024, Steven Yen escreveu:
>>> I need to read csv files repeatedly, n
In my package HelpersMG, I have included a function to read in one time
all the files of a folder and they are stored in a list:
read_folder(
folder = try(file.choose(), silent = TRUE),
file = NULL,
wildcard = "*.*",
read = read.delim,
...
)
In your case, for example:
library("Helper
Às 03:27 de 19/02/2024, Steven Yen escreveu:
I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv,
24 altogether. That is,
data<-read.csv(“data1.csv”)
…
data<-read.csv(“data24.csv”)
…
Is there a way to do this in a loop? Thank you.
Steven from iPhone
[[alternat
f <- function (filename) {
data<- read.csv(filename)
..
}
for (filename in paste0("data", 1:24, ".csv")) f(filename)
Depending on what exactly you have in your file system,
for (filename in system("ls data*.csv", TRUE)) f(filename)
might work.
On Mon, 19 Feb 2024 at 16:33, Steven Yen wrote
Steven,
It depends what you want to do. What you are showing seems to replace the
values stored in "data" each time.
Many kinds of loops will do that, with one simple way being to store all the
filenames in a list and loop on the contents of the list as arguments to
read.csv.
Since you show f
Try
for (ind in 1:24)
{
data = read.csv(paste0("data", ind, ".csv"))
...
}
Peter
On Mon, Feb 19, 2024 at 11:33 AM Steven Yen wrote:
>
> I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv,
> 24 altogether. That is,
>
> data<-read.csv(“data1.csv”)
> …
> data<-rea
Hi Paul,
I am not sure I understand your question, but perhaps the following is helpful.
In particular, the apply() function used with MAR=1, applies a
function to a matrix row-wise.
set.seed(123)
m <- matrix(sample(1:6,5*12,replace=TRUE),ncol=12) ## dummy data
m
[,1] [,2] [,3] [,4] [,5] [,6]
Well, if I understand your query, wouldn't the following simple approach
suffice -- it assumes that the results for each company are ordered by
year, as your example seems to show:
## test is your example data
## first remove NA's
test2 <- na.omit(test)
## Now just use tapply():
> out <-with(test
Rui, excellent diagnosis and suggestion. It worked but my damn logic is still
not delivering what I want-will spend more time on it tomorrow.
Kind regards
Ahson
> On 13 April 2021 at 17:06 Rui Barradas wrote:
>
>
> Hello,
>
> A close parenthesis is missing in the nd if.
>
>
> for (i in 1
Jim, thanks for taking the time to look into this. Yes, these if else
statements are so confusing.
I tried your amended scode and it does not work. The error are as follows:
Error: unexpected '}' in " }"
> NUMBER_OF_SHARES[i] = 100 / is.na(CLOSE_SHARE_PRICE[i])
> }
Error: unexpected '}' in " }"
Hello,
Typo, inline.
Às 17:06 de 13/04/21, Rui Barradas escreveu:
Hello,
A close parenthesis is missing in the nd if.
Should be "the 2nd if".
Rui Barradas
for (i in 1:(nrow(PLC_Return)-1)){
if (i == 1){
NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])
} else if(is.na(PLC
Hello,
A close parenthesis is missing in the nd if.
for (i in 1:(nrow(PLC_Return)-1)){
if (i == 1){
NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])
} else if(is.na(PLC_Return[i, 1]) == is.na(PLC_Return[i + 1, 1])){
NUMBER_OF_SHARES[i]=0
} else {
NUMBER_OF_SHARES[i] = 100
Your code was formatted incorrectly. There is always a problem with the
'else' statement after an 'if' since in R there is no semicolon to mark the
end of a line. Here might be a better format for your code. I would
recommend the liberal use of "{}"s when using 'if/else'
i <- 0
for (i in 1:(
> library(dplyr, warn.conflicts=FALSE)
> d <- data.frame(Company=c("MATH","IFUL","SSI","MATH","MATH","SSI"),
> Turnover=c(2,3,5,7,9,11))
> d %>% group_by(Company) %>% summarize(Count=n(), MeanTurnover=mean(Turnover),
> TotalTurnover=sum(Turnover))
`summarise()` ungrouping output (override with `.
Hi,
Your sample code suggests that you don't yet understand how R works,
and might benefit from a tutorial or two. However, your verbal
description of what you want is quite straightforward. Here's a
R-style way to count the number of times each company appears, and to
get the mean value of Turnov
Bert, thanks for responding to my email. I do realise that newbie's like my can
expect curt answers but not to worry. I am definitely learning 'R' and what I
posted are also statements from R. The statements run perfectly well but don't
do what I want them to do. My mistake I have posted sample
Hi Ahson,
Guessing what your data frame might look like, here are two easy ways:
All_companies<-data.frame(year=c(1970:2015,2000:2015,2010:2015),
COMPANY_NUMBER=c(rep(1,46),rep(2,16),rep(3,6)),
COMPANY_NAME=c(rep("IBM",46),rep("AMAZON",16),rep("SPACE-X",6)))
# easy ways
table(All_companies$COMPA
What you are asking is one area where the package data.table really
shines. You didn't provide an example, but based on your question you
would do something like:
library(data.table)
dt <- as.data.table(All_companies)
dt[, .N, by=COMPANY_NAME]
You will have to read up on data.table, but .N gives
It occurs to me a simple table command will do what you say you want but I
suspect the real analysis is more complicated
dat1 <- data.frame(aa = sample(letters[1:5], 10, replace = TRUE),
bb = 1:10)
table(dat1$aa)
On Tue, 21 Jul 2020 at 14:01, John Kane wrote:
> As Bert says th
As Bert says that does not look like R
Have a look an these links for some suggestions on asking questions here.
http://adv-r.had.co.nz/Reproducibility.html
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
On Tue, 21 Jul 2020 at 13:42, Bert Gunter wrote:
What language are you programming in? -- it certainly isn't R.
I suggest that you stop what you're doing and go through an R tutorial or
two before proceeding. This list cannot serve as a substitute for doing
such homework (is this homework, btw? -- that's off topic here) nor can we
provide such t
Thank you very much, Dr. Snow, your suggestion helps a lot.
Best,
Saat
On Fri, Apr 19, 2019 at 4:14 AM Greg Snow <538...@gmail.com> wrote:
> When the goal of looping is to compute something and save each
> iteration into a vector or list, then it is usually easier to use the
> lapply/sapply/repl
When the goal of looping is to compute something and save each
iteration into a vector or list, then it is usually easier to use the
lapply/sapply/replicate functions and save the result into a single
list rather than a bunch of global variables.
Here is a quick example that does the same computat
You really need to spend some time learning the basics of R. There are
thousands of R packages, so you also need to spend time reading the
documentation for the package so that you can show us what the data format
should be like. Here are some simple ways to transform the data. You should
also
Dear Li
Not absolutely sure what you want to do but try
?aggregate
?by
?apply (or one of the other apply functions, possibly tapply
On 19/10/2017 11:29, Li Jiang wrote:
Hi everyone,
I'm new at R (although I'm a Stata user for some time and somehow
proficient in it) and I'm trying to use the '
Use auto.assign = FALSE in your getFinancials() call, and use
viewFinancials() to extract the data you want.
items <- c("Cash & Equivalents",
"Short Term Investments",
"Cash and Short Term Investments")
tickers <- c("AAPL", "IBM", "MSFT")
for (ticker in tickers) {
Data <- g
4 5 4 3 6 4 3 4 5 ...
$ Transit: Date, format: "1985-10-01" "1985-11-01" ...
Would be preferable.
-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352
From: Paul Bernal [mailto:paulberna...
-Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul
> Bernal
> Sent: Tuesday, March 28, 2017 9:12 AM
> To: Ng Bo Lin
> Cc: r-help@r-project.org
> Subject: Re: [R] Looping Through DataFrames with Differing Lenghts
>
> Dear friends Ng Bo Li
Hi Paul,
Using the example provided by Ulrik, where
> exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”,
> "1986-01-01"), Transits = c(NA, NA, NA, NA))
> exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits =
> c(15,20)),
You could also try the following funct
Hi Paul,
The date format that you have supplied to R isn’t exactly right.
Instead of supplying the format “%Y-%m-%d”, it appears that the format of your
data adheres to the “%e-%B-%y” format. In this case, %e refers to Day, and
takes an integer between (0 - 31), %B refers to the 3 letter abbrev
College Station, TX 77840-4352
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Bernal
Sent: Tuesday, March 28, 2017 9:12 AM
To: Ng Bo Lin
Cc: r-help@r-project.org
Subject: Re: [R] Looping Through DataFrames with Differing Lenghts
Dear friends Ng Bo Lin, Mark and
Dear Bo Lin,
I tried doing
Containerdata$TransitDate<-as.Date(Containerdata$TransitDate, "%e-%B-%y")
but I keep getting NAs.
I also tried a solution that I saw in stackoverflow doing:
> lct<-Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
[1] "C"
>
> Sys.setlocale("LC_TIME", lct)
[1] "En
Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and
valuable replies,
I am trying to reformat a date as follows:
Data<-read.csv("Container.csv")
DataFrame<-data.frame(Data)
DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d")
#trying to put it in -MM-DD for
Hi Paul,
does this do what you want?
exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01",
"1986-01-01"), Transits = c(NA, NA, NA, NA))
exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = c(15,
20))
tmpdf <- subset(exdf1, !Date %in% exdf2$Date)
rbind(exdf2, tmp
Dear friend Mark,
Great suggestion! Thank you for replying.
I have two dataframes, dataframe1 and dataframe2.
dataframe1 has two columns, one with the dates in -MM-DD format and the
other colum with number of transits (all of which were set to NA values).
dataframe1 starts in 1985-10-01 (oct
Hi Paul,
match might help, but without a real data sample, it is hard to check if the
following might work.
mm=match(df.col378[,"Date"],df.col362[,"Date"])
#mm will have NAs, where there is no matching date in df.col362
#and have the index of the match, where the two dates match
new.df=cbind(df.
You could use merge() or %in%.
Best,
Ulrik
Mark Sharp schrieb am Mo., 27. März 2017, 22:20:
> Make some small dataframes of just a few rows that illustrate the problem
> structure. Make a third that has the result you want. You will get an
> answer very quickly. Without a self-contained reprodu
Make some small dataframes of just a few rows that illustrate the problem
structure. Make a third that has the result you want. You will get an answer
very quickly. Without a self-contained reproducible problem, results vary.
Mark
R. Mark Sharp, Ph.D.
msh...@txbiomed.org
> On Mar 27, 2017,
help [mailto:r-help-boun...@r-project.org] On Behalf Of greg
> holly
> > Sent: Thursday, February 2, 2017 4:13 PM
> > To: Rui Barradas
> > Cc: r-help mailing list
> > Subject: Re: [R] looping problem
> >
> > Thanks so much for this. Unfortunately, cbind did no
-40 which are basic for
data input and manipulation.
Cheers
Petr
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of greg holly
> Sent: Thursday, February 2, 2017 4:13 PM
> To: Rui Barradas
> Cc: r-help mailing list
> Subject: Re
Thanks so much for this. Unfortunately, cbind did not work. Basically, I
like to put an extra column named "chr" in the combined file from 22 chr.
So chr colum will be "1" for the portion of chr1 in the combined file, 2
for the portion of chr2 in the combined file and so on.
Regards,
Greg
On Thu
Hello,
If I understand correctly, just use ?cbind.
Rui Barradas
Em 02-02-2017 13:33, greg holly escreveu:
Hi Rui;
Is there any way to insert the chr ids in numeric as 1,2..,22 in the
final output. Here is output from str(temp). So I need also chr ids in a
column.
1 rs58108140 105
Hi Rui;
Is there any way to insert the chr ids in numeric as 1,2..,22 in the
final output. Here is output from str(temp). So I need also chr ids in a
column.
1 rs58108140 10583 G A -0.070438 0.059903
2 rs189107123 10611 C G -0.044916 0.085853
Regards,
Greg
On Wed, Feb 1, 20
Hi Rui;
I do appreciate for this. Thanks so much. I will try ASAP.
Regards,
Greg
On Wed, Feb 1, 2017 at 1:32 PM, Rui Barradas wrote:
> Hello,
>
> If what you want is to combine the files into one data.frame then there
> are 2 things you should see:
>
> 1) You create a variable named 'temp' an
Hello,
If what you want is to combine the files into one data.frame then there
are 2 things you should see:
1) You create a variable named 'temp' and don't ever use it.
2) You never combine the data.frames you read in.
Try instead the following.
temp <- data.frame()
for(i in 1:22) {
infi
On Mon, 3 Oct 2016, Frank S. wrote:
Dear R users,
[deleted]
I want to get a list of "k" data tables (or data frames) so that each
contains those individuals who for the first time are at least 65,
looping on each of the dates of vector "v". Let's consider the following
example with 5 ind
Hi Frank,
How about
library(lubridate)
dtf <- merge(dt, expand.grid(id = dt$id, refdate = v), by = "id")
dtf[, gt65 := as.period(interval(fborn, refdate), unit = "years") > years(65)]
dtf <- dtf[gt65 == TRUE,][, .SD[refdate == min(refdate)], by = id]
Best,
Ista
On Mon, Oct 3, 2016 at 1:17 PM, F
Thanks so much everybody, especially to Dennis. I didn't really occur to me
that I could put the models into a list. I have used dplyr for simple data
transformations and will definitely look into it.
On Thu, Sep 1, 2016 at 8:10 AM, Dennis Murphy wrote:
> Hi:
>
> See inline.
>
> On Wed, Aug 31,
Hi Kai,
Perhaps something like this:
kmdf<-data.frame(group=rep(c("exp","cont"),each=50),
time=factor(rep(1:5,20)),
condition=rep(rep(c("hot","cold"),each=25),2),
value=sample(100:200,100))
for(timeindx in levels(kmdf$time)) {
for(condindx in levels(kmdf$condition)) {
cat("Time",timeindx,"Co
Kai:
1. I think that this is a very bad idea, statistically, if I
understand you correctly. Generally, your model should incorporate all
groups, time points, and conditions together, not individually.
2. But plotting results in "small multiples" -- aka "trellis plots"
may be useful. This is done
Or sorry, I should clarify, I struggle with putting components together when it
comes to looping.
On Thursday, December 3, 2015 11:43 AM, debra ragland
wrote:
Thanks again!
And no Bert, this is not homework. I have a very minimal background in R and
struggle with putting concepts together.
Thanks again!
And no Bert, this is not homework. I have a very minimal background in R and
struggle with putting concepts together.
But thanks anyway.
On Thursday, December 3, 2015 11:04 AM, Boris Steipe
wrote:
Use your logical vector to extract the x, y values for the test from the rows
Use your logical vector to extract the x, y values for the test from the rows
of the matrix:
x <- mat[3, x2]
y <- mat[3, !x2]
Or: use the formula version of wilcox.test as explained in ?wilcox.test
B.
On Dec 3, 2015, at 10:28 AM, debra ragland via R-help
wrote:
> I have read in a seque
I should have added -- is this homework? There is a no homework policy
on this list.
Bert Gunter
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
-- Clifford Stoll
On Thu, Dec 3, 2015 at 7:54 AM, Bert Gunter wrote:
> Have you spent any time wit
First, a couple posting tips. It's helpful to provide some example data
people can work with. Also, please post in plain text (not html).
If you have a single standard for comparison, you might find an approach
like this helpful.
# example data
mylist <- c("AAEBCC", "AABDCC", "AABBCD")
list.2 <
Hi April,
You need nested loops for something like this
qs<- c(0,0.25,0.5,1,2,4,8,16,32,64)
nrows<-dim(Data)[1]
nqs<-length(qs)
D.mat<-SE.mat<-matrix(NA,nrow=nrows,ncol=nqs)
for(row in 1:nrows) {
for(qval in 1:nqs) {
# perform your calculation and set D.mat[row,qval] and
SE.mat[row,qval] to the
Hi
Your question is a bit cloudy. Simple loop can be realised to populate lists
res<-vector(100, "list")
for (i in 1:100) {
lll <- do something based on i value
res[[i]] <- put lll in ith place of the list
}
Cheers
Petr
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-pro
participant.files <- list.files("/Users/cdanyluck/Documents/Studies/MIG -
Dissertation/Data & Syntax/MIG_RAW DATA & TXT Files/Plain Text Files")
Try adding the argument full.names=TRUE to that call to list.files().
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Mon, Jun 8, 2015 at 7:15 PM, C
Thank you Don.
I've incorporated your suggestions which have helped me to understand how
loops work better than previously. However, the loop gets stuck trying to
read the current file:
mig.processed.data <- read.csv("/Users/cdanyluck/Documents/Studies/MIG -
Dissertation/Data & Syntax/mig.log.dat
So you have 80 files, one for each participant?
It appears that from each of the 80 files you want to extract three
subsets of rows,
one set for baseline
one set for audio
one set for "free"
What I think I would do, if the above is correct, is create one "master"
file. This file will have e
On 03/03/15 16:08, Jeff Newmiller wrote:
Sigh. To be positive is to be wrong at the top of one's lungs. Next I
will be told R has a goto statement.
I am ***positive*** that it hasn't! :-) Well, 99.999% confident.
Although I guess it's not inconceivable that some misguided nerd might
constr
Sigh. To be positive is to be wrong at the top of one's lungs. Next I will be
told R has a goto statement.
---
Jeff NewmillerThe . . Go Live...
DCN:Basics: ##.#. ##.#.
On 03/03/15 15:04, Jeff Newmiller wrote:
Your example is decidedly not expressed in R, though it looks like
you tried. Can you provide the hand-computed result that you are
trying to obtain?
Note that the reason you cannot find anything about next or break in
R is that they don't exist.
Point
Your example is decidedly not expressed in R, though it looks like you tried.
Can you provide the hand-computed result that you are trying to obtain?
Note that the reason you cannot find anything about next or break in R is that
they don't exist. There are generally alternative ways to accomplis
Hi efisio,
Okay, you can switch devices using the dev.* functions in the grDevices
package. If you only have two devices open at one time, this is not too
difficult:
#open both devices
png(...)
par(mfrow=c(1,2))
png(...)
par(mfrow=c(1,2))
hist(...)
dev.set(dev.next())
hist(...)
dev.set(dev.next())
Thanks Jim,
actually I need to keep open two devices at the same time, and within
the loop access either of them in alternation. In MatLab there is the
command Figure(#) which keeps track of the open devices and direct the
output of the plot to whichever of them.
For example:
plot_filenames<-c(
Hi efisio,
I read this as wanting to start a new graphics device, then set some plot
parameters, display two plots and then close the graphics device at each
iteration of the loop. If so,
plot_filenames<-c("plot1.png","plot2.png","plot3.png")
for(plotfn in plot_filenames) {
png(plotfn)
par(mfrow
On 02/04/2014, 3:15 PM, Abugri James wrote:
I ran the following loop on my SNP data and got an error message as
indicated
I would assume that the error message is accurate:
as.character(current[1, "gene_old"]) has length zero. You'll need to
debug why that happened.
Duncan Murdoch
for (i
You desperately need to read the Posting Guide (mentioned in the footer of this
email) which warns you not to post in HTML format, and learn how to make a
reproducible example (e.g.
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example).
The problem lies in some
Hi Alex,
Not sure if this is what you wanted.
length(res) #from the previous 'example' using ##indx <-
combn(dim(results)[1],2)
#[1] 45
mat1 <- matrix(0,10,10)
mat1[lower.tri(mat1)] <- res
mat1[upper.tri(mat1)] <- res
A.K.
On Saturday, January 11, 2014 12:22 AM, alex padron
wro
It seems like emdist does not like to compare matrices with all 0 values. I
ended up removing those from my 3D array and have ~8000 matrices instead of
13000.
I am using res2 <- unlist(mclapply(seq_len(ncol(indx)),function(i) {x1 <-
indx[,i]; emd2d(results[x1[1],,],results[x1[2],,]) }) )
But even
Hi,
No problem.
You can use ?lower.tri() or ?upper.tri()
res[lower.tri(res)]
res[lower.tri(res,diag=TRUE)]
#Other way would be to use:
?combn
indx <- combn(dim(results)[1],m=2)
res2 <- sapply(seq_len(ncol(indx)),function(i) {x1 <- indx[,i];
emd2d(results[x1[1],,],results[x1[2],,]) })
identical
Hi,
Try:
library(emdist)
set.seed(435)
results<- array(sample(1:400,120,replace=TRUE),dim=c(10,3,4))
res <- sapply(seq(dim(results)[1]),function(i) {x1 <- results[i,,]; x2 <-
results; sapply(seq(dim(x2)[1]),function(i) emd2d(x1,x2[i,,]))})
dim(res)
#[1] 10 10
A.K.
On Thursday, January 9, 2
HI,
I tested it on R 3.0.2 console (linux) and also on Rstudio Version 0.98.490.
It seems alright.
A.K.
Thanks for this. I am trying to run the code you posted but Rstudio keeps
crashing. I am trying to run it on the example output1 since it's small but
that crashes as well.
On Thursday
#or
mapply(emd2d,sapply(output1,`[`,1),sapply(output1,`[`,2))
#[1] NaN -6.089909
A.K.
On Thursday, January 2, 2014 2:33 PM, arun wrote:
Hi,
May be this helps:
set.seed(42)
output1 <- list(list(matrix(0,8,11),matrix(0,8,11)),
list(matrix(rnorm(80),8,10),matrix(rnorm(80),8,10)))
libra
Hi,
May be this helps:
set.seed(42)
output1 <- list(list(matrix(0,8,11),matrix(0,8,11)),
list(matrix(rnorm(80),8,10),matrix(rnorm(80),8,10)))
library(emdist)
sapply(output1,function(x) {emd2d(x[[seq_along(x)[1]]],x[[seq_along(x)[2]]]) })
#[1] NaN -6.089909
A.K.
I'm trying to apply a fu
Hi,
May be this helps:
Using your function:
mapply(less,test,4)
#or
invisible(mapply(less,test,4))
#[1] 2 3
#[1] 3
#or
for(i in 1:ncol(test)){
less(test[,i],4)}
#[1] 2 3
#[1] 3
A.K.
Hi, I'm trying to figure out how to loop through columns in a matrix or
data frame, but what I've been f
You might want to try:
assign(d[1], read.csv("yourfile.csv"))
...
write.csv(d1, "yourfile.csv", append = FALSE)
Regards
Mikkel
On Friday, October 11, 2013 2:53 PM, Dan Abner wrote:
Hi everybody,
I thought I was using the get() fn correctly here to loop over multiple
data frame names in an
I think you want 'assign' at that point. Would suggest using a 'list'
to store the input instead of unique named objects. 'list's are
easier to manage.
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.
On Fri
Hi,
Try:
dat2<- read.csv("BOlValues.csv",header=TRUE,sep="\t",row.names=1)
dim(dat2)
#[1] 20 28
indx2<-expand.grid(names(dat2),names(dat2),stringsAsFactors=FALSE)
nrow(indx2)
#[1] 784
indx2New<- indx2[indx2[,1]!=indx2[,2],]
nrow(indx2New)
#[1] 756
res2<-sapply(seq_len(nrow(indx2New)),function(i
HI,
Using the example dataset (Test_data.csv):
dat1<- read.csv("Test_data.csv",header=TRUE,sep="\t",row.names=1)
indx2<-expand.grid(names(dat1),names(dat1),stringsAsFactors=FALSE)
indx2New<- indx2[indx2[,1]!=indx2[,2],]
res2<-t(sapply(seq_len(nrow(indx2New)),function(i) {x1<- indx2New[i,];
x2<-c
HI,
May be this helps:
set.seed(28)
dat1<-
setNames(as.data.frame(matrix(sample(1:40,10*5,replace=TRUE),ncol=5)),letters[1:5])
indx<-as.data.frame(combn(names(dat1),2),stringsAsFactors=FALSE)
res<-t(sapply(indx,function(x)
{x1<-cbind(dat1[x[1]],dat1[x[2]]);summary(lm(x1[,1]~x1[,2]))$coef[,4]}))
Hello Arun. Can you provide some data? To help you better i will need a
complete reproducible example ok?
On Thu, Sep 5, 2013 at 1:49 PM, arun wrote:
> HI,
> May be this helps:
> set.seed(28)
> dat1<-
> setNames(as.data.frame(matrix(sample(1:40,10*5,replace=TRUE),ncol=5)),letters[1:5])
> indx
On Jun 24, 2013, at 12:13 AM, Fazli Raziq wrote:
> Hello all,
>
> I want to construct "Two way Matrix". The Algorithm is like:
>
> 1) Data of time with censoring or events
> 2) Predictor variables (genes)
> 3) Resample original data in step 1 and 2 by WR
> 4) Apply Coxph Model to resample d
On Apr 29, 2013, at 6:03 PM, Sparks, John James wrote:
> Dear R Helpers,
>
> I am re-phrasing a question that I put forth earlier today due to some
> particulars in the solution that I am searching for. Many thanks to those
> who answered the previous post and to any who would be willing to ans
Much thanks Blaser. That worked perfectly. This will improve my code
considerably. Greatly appreciated.
Regards,
Dan
On Fri, Apr 26, 2013 at 3:48 AM, Blaser Nello wrote:
> Here are two possible ways to do it:
>
> This would simplify your code a bit. But it changes the names of x_cs to
> cs.x.
Here are two possible ways to do it:
This would simplify your code a bit. But it changes the names of x_cs to
cs.x.
for (df in nls) {
assign(df, cbind(get(df), cs=apply(get(df), 2, cumsum)))
}
This is closer to what you have done.
for (df in nls) {
print(df)
for (var in names(get(df)))
Thanks a lot, Pratap!
Dimitri
On Mon, Feb 4, 2013 at 9:43 AM, nalluri pratap wrote:
> Just modified your code a bit, hope this helps:
>
> a=expand.grid(1:2,1:2)
> b=expand.grid(1:2,1:2,1:2)
> c=expand.grid(1:2,1:2,1:2,1:2)
> l.long<-list(a,b,c)
> mygrid<-do.call(expand.grid,lapply(l.long,funct
Just modified your code a bit, hope this helps:
a=expand.grid(1:2,1:2)
b=expand.grid(1:2,1:2,1:2)
c=expand.grid(1:2,1:2,1:2,1:2)
l.long<-list(a,b,c)
mygrid<-do.call(expand.grid,lapply(l.long,function(x) 1:nrow(x)))
out<-vector("list",nrow(mygrid))
for(gridrow in 1:nrow(mygrid))
{
sum_rows=0
Tilottama Ghosh yahoo.com> writes:
>
> Hi,
> Following Anthony's reply I am attaching two of the POI shapefiles and the
code for creating the spatial
> grid. I am not being able to read the list of these shapefiles and then
perform the points in spatial grid
> function. If someone can help, I wi
Hi,
Following Anthony's reply I am attaching two of the POI shapefiles and the code
for creating the spatial grid. I am not being able to read the list of these
shapefiles and then perform the points in spatial grid function. If someone can
help, I will be very grateful.
Here is my code for crea
Sample data?
Please supply some sample data and code.
The easiest way to supply data is to use the dput() function. Example with
your file named "testfile":
dput(testfile)
Then copy the output and paste into your email. For large data sets, you can
just supply a representative sample.
On Thu, Nov 8, 2012 at 6:16 PM, Nordlund, Dan (DSHS/RDA)
wrote:
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
>> project.org] On Behalf Of wilkesma
>> Sent: Thursday, November 08, 2012 5:49 AM
>> To: r-help@r-project.org
>> Subject: [R] Looping mat
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of wilkesma
> Sent: Thursday, November 08, 2012 5:49 AM
> To: r-help@r-project.org
> Subject: [R] Looping matrix multiplication
>
> I am dealing with a number of time-series consis
Thank you for all your responses, I assure you this is not homework. I am
a graduate student and my classes are complete. I am trying multiple
different ways to analyze data and my lab requests different types of
scripts to accomplish various tasks. I am the most computer savy in the
lab so it c
The number of recent questions from umn.edu makes me wonder if there's homework
involved
Simpler for your example is to use get and subset.
dat <- structure(.as found below
var.to.test <- names(dat)[4:6] #variables of interest
nvar <- length(var.to.test)
chisq <- double(nvar)
for (
> sapply(seq(4,ncol(dat)), function(i)
> survdiff(Surv(time,completion=="2")~dat[,i], data=dat,
> subset=group=="3")$chisq)
[1] 0.0944 4.4854 3.4990
Chris
-Original Message-
From: Charles Determan Jr [mailto:deter...@umn.edu]
Sent: Thursday, October 18, 2012 3:04 PM
To: r-help@r-projec
Thank you, character indexing (?"[") is what I was looking for:
sapply(paste('var', 1:100, sep=''), function(x)
weighted.mean(data[[x]], data$weight))
Daniel
On Mon, Aug 27, 2012 at 6:26 PM, Bert Gunter wrote:
> Have you read "An Introduction to R". If not, please do so before
> osting and pay
On Aug 27, 2012, at 7:11 AM, Daniel Caro wrote:
Hello,
This is a beginner question.
You should read the Posting Guide. (As well as following Bert's
suggestion to work through "Intro to R".
I am trying to loop through numbered
variables with "apply" to calculate weighted means. My data i
Have you read "An Introduction to R". If not, please do so before
osting and pay particular attention to the section on indexing. If so,
re-read the sections on indexing.
For a terser exposition, ?"["
-- Bert
On Mon, Aug 27, 2012 at 7:11 AM, Daniel Caro wrote:
> Hello,
>
> This is a beginner qu
1 - 100 of 192 matches
Mail list logo