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
8, 2024 10:28 PM
To: R-help Mailing List
Subject: [R] Looping
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.
St
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
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
[[alternative HTML version deleted]]
__
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]
Dear R friends,
One question, so, thanks to the Bert's kind feedback, I was able to create
my matrix using the following code:
dice_rolls = 120
num_dice = 1
dice_sides = 6
#performing simulation
dice_simul = data.frame(dice(rolls = dice_rolls, ndice = num_dice, sides =
dice_sides, plot.it = TRU
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:(
Dear All,I have a dataframe with 4 variables and I am trying to calculate how
many shares can be purchased with £100 in the first year when the company was
listed
The data looks like:
COMPANY_NUMBER YEAR_END_DATE CLOSE_SHARE_PRICE NUMBER_OF_SHARES
2270530/09/200
> 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
Dear All, I have a dataframe which has a few thousand companies with unique
company numbers and names and each company has data for several years and each
year is stored in a separate row.
I want to get a total for the number of years of data for each company. When I
loop through the data with
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
Dear R community,
I'm trying to create a looping to see the effect of number of samples from
one dataset.
Lets say I have 10 values in a single data frame and I want to see the mean
of each sampling let say from 2-9 number of sampling. But I want to do the
repetition let say up to 100 for each num
ent of Anthropology
Texas A&M University
College Station, TX 77843-4352
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Li Jiang
Sent: Thursday, October 19, 2017 4:08 AM
To: r-help@r-project.org
Subject: [R] looping using 'diverse' package meas
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 '
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 'diverse' R package to compute
a few diversity measures on a sample of firms for a period of about 10
years. I was wondering if you can give me some hints on how to best proce
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 'diverse' R package to compute
a few diversity measures on a sample of firms for a period of about 10
years. I was wondering if you can give me some hints on how to best proce
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
Dear R Helpers,
I have run into a problem trying to perform a number of actions on a set
of quantmod data objects through a loop and I am hoping that this is an
easy problem for someone else as opposed to very difficult for me.
The example task is to get the first three objects of the quarterly
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,
Dear friends,
I have one dataframe which contains 378 observations, and another one,
containing 362 observations.
Both dataframes have two columns, one date column and another one with the
number of transits.
I wanted to come up with a code so that I could fill in the dates that are
missing in o
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
Hi all;
I have 22 directories named chr1, chr2,,chr22. Each directory has a
file named "Z-score.imputed". I would like to combine Z-score.imputed
files into one. I wrote the following loop but did not get any results.
Your helps are highly appreciated.
regards,
Greg
temp<-c()
for(i in 1:2
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
Hi all,
I am having trouble wrapping my head around a probably simple issue:
After using the reshape package, I have a melted dataframe with the columns
group (factor), time (int), condition (factor), value(int).
These are experimental data. The data were obtained from different
treatment groups
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
I have read in a sequence alignment and have done the necessary steps to
separate and store the elements of the original input into a new list of
character vectors. I have compared the sequence list to a "standard" vector,
such that the return is a matrix of logical values indicating TRUE if the
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 <
I think I am making this problem harder than it has to be and so I keep getting
stuck on what might be a trivial problem.
I have used the seqinr package to load a protein sequence alignment containing
15 protein sequences;
> library(seqinr) > x =
read.alignment("proteins.fasta",format="f
at[row,qval] to the return values
}
}
Jim
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of April
> Smith
> Sent: Friday, July 31, 2015 2:21 AM
> To: r-help@r-project.org
> Subject: [R] Looping help
>
> I have never looped before and know I need to. I am unsure
[mailto:r-help-boun...@r-project.org] On Behalf Of April
> Smith
> Sent: Friday, July 31, 2015 2:21 AM
> To: r-help@r-project.org
> Subject: [R] Looping help
>
> I have never looped before and know I need to. I am unsure how to
> proceed:
>
>
>- Action I need do
I have never looped before and know I need to. I am unsure how to proceed:
- Action I need done: d(Data[1,2:399], q=0, boot=TRUE,
boot.arg=list(num.iter=1000))
- I need this to happen to all rows, I need All[1,2:399] to increase to
All[2:399], etc.
- But I also need the results fr
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
Hello,
I want to subset specific rows of data from 80 .csv files and write those
subsets into new .csv files. The data I want to subset starts on a
different row for each original .csv file. I've created variables that
identify which row the subset should start and end on, but I want to loop
throu
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
Hello,
I apologies for bringing up next and break in loops given that there is so
much on the net about it, but I've tried numerous examples found using
Google and just can't seem to get this to work.
This is a simple version of what I am doing with matrices but it shows the
issue. I need to have
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
Dear,
cannot find a way to direct multipanel plots to different figures
(files) while within a loop.
Say, the loop creates two plots each step: one plot should go to figure
1 and the other to figure 2.
Same for the next steps of the loop: the plots should go to figure 1
and figure 2 in a m
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
I ran the following loop on my SNP data and got an error message as
indicated
for (i in genenames){
+ current <- fst1[which(fst1$Gene == i),]
+ num <- nrow(current)
+ fst <- max(current$fst)
+ position <- mean(current$pos)
+ nposition <- mean(current$newpos)
+ numhigh <- nrow(current[wh
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 everybody,
I thought I was using the get() fn correctly here to loop over multiple
data frame names in an R for() loop. Can someone advise?
> miss<-c("#NULL!","999")
> d<-c("d1","d2","d3","d4")
>
> for(i in 1:4){
+
+ miss1<-ifelse(i<=2,miss[1],miss[2])
+ miss1
+
+ get(d[i])<-read.csv(paste("C
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
1 - 100 of 267 matches
Mail list logo