Displaying 20 results from an estimated 3000 matches similar to: "Logical operator and lists"
2012 Nov 08
3
Extracting columns
Hi,
I have 22 files (A1, A2, ..., A22) with different number of columns,
totaling 10,000 columns: c1, c2, c3, ..., c10000
I have another file with a list of 100 columns that I need to extract.
These 100 columns are distributed in 22 files.
How to extract the 100 columns of the 22 files?
I have done it "manually" with the following commands, for example:
cromo1 = read.table ("~
2017 Dec 04
3
Dynamic reference, right-hand side of function
Hi R-users!
Being new to R, and a fairly advanced Stata-user, I guess part of my problem is that my mindset (and probably my language as well) is wrong. Anyway, I have what I guess is a rather simple problem, that I now without success spent days trying to solve.
I have a bunch of datasets imported from Stata that is labelled aa_2000 aa_2001 aa_2002, etc. Each dataset is imported as a matrix, and
2013 Apr 03
2
Creating data frame from individual files
Dear Group:
I have 72 files (.txt).
Each file has 2 columns and column 1 is always identical for all 70 files.
Each file has 90,799 rows and is standard across all files.
I want to create a matrix 40(rows) x 70 columns.
I tried :
temp = list.files(pattern="*.txt")
named.list <- lapply(temp, read.delim)
library(data.table)
files.matrix <-rbindlist(named.list)
>
2017 Dec 04
3
Dynamic reference, right-hand side of function
Hi!
Thanks for the replies!
I understand people more accustomed to R doesn't like looping much, and that thinking about loops is something I do since I worked with Stata a lot. The syntax from Peter Dalgaard was really clever, and I learned a lot from it, even though it didn't solve my problem (I guess it wasn't very well explained). My problem was basically that I have a data matrix
2013 Jan 02
4
list of matrices
dear useRs,
i have a list containing 16 matrices. i want to calculate the column mean of each of them.
i tried
>sr <- lapply(s,function(x) colMeans(x, na.rm=TRUE))
but i am getting the following error
>Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric
can it be done in any other way? and why i am getting this error??
thanks in advance..
elisa
[[alternative
2017 Dec 04
0
Dynamic reference, right-hand side of function
The generic rule is that R is not a macro language, so looping of names of things gets awkward. It is usually easier to use compound objects like lists and iterate over them. E.g.
datanames <- paste0("aa_", 2000:2007)
datalist <- lapply(datanames, get)
names(datalist) <- datanames
col1 <- lapply(datalist, "[[", 1)
colnum <- lapply(col1, as.numeric)
(The 2nd
2017 Dec 04
0
Dynamic reference, right-hand side of function
Um, if you insist on doing it that way, at least use
assign(varname, as.vector(get(varname)))
-pd
> On 4 Dec 2017, at 22:46 , Love Bohman <love.bohman at sociology.su.se> wrote:
>
> Hi!
> Thanks for the replies!
> I understand people more accustomed to R doesn't like looping much, and that thinking about loops is something I do since I worked with Stata a lot. The
2011 Dec 28
3
transparency using plot+points with sp classes
How can I make one point graphics with transparency
These are all sp classes:
plot(polygons_area,axes=TRUE,asp=1.5,main="Title",xlab="Latitude",
ylab="Longitude")
points(observations2000,type = "p",pch=21,col="green")
points(observation1999,type = "p",pch=21,col="blue")
points(reference.points,type =
2017 Dec 04
2
Dynamic reference, right-hand side of function
:-)
I don't insist on anything, I'm just struggling to learn a new language and partly a new way of thinking, and I really appreciate the corrections. I hope I someday will be able to handle lists in R as easy as I handle loops in Stata...
Thanks again!
Love
-----Ursprungligt meddelande-----
Fr?n: peter dalgaard [mailto:pdalgd at gmail.com]
Skickat: den 4 december 2017 23:09
Till:
2012 Nov 09
1
Mean of matrices entries in list of lists
Hey there,
I've got a list of lists with matrices:
A list with 13 entries (representing years), each of them another list with
12 matrices (representing one month). In each matrix there are as many rows
as there are hours in the different months and 2 columns, since two
meteorological parameters are measured.
What I want to do is to calculate the hourly mean values for each month over
the
2013 Feb 19
1
data format
Hi,
Try this:
el<- read.csv("el.csv",header=TRUE,sep="\t",stringsAsFactors=FALSE)
?elsplit<- split(el,el$st)
?
datetrial<-data.frame(date1=seq.Date(as.Date("1930.1.1",format="%Y.%m.%d"),as.Date("2010.12.31",format="%Y.%m.%d"),by="day"))
elsplit1<- lapply(elsplit,function(x)
2017 Dec 05
3
Dynamic reference, right-hand side of function
Hi again!
I know you don't find loops evil (well, at least not diabolic :-) ). (After many hours googling I have realized that thinking about loops rather than lists is a newbie thing we Stata-users do, I just jokingly pointed it out). Anyway, I'm really happy that you try to teach me some R-manners. Since I still get questions about what the h**k I mean by my strange question, I sort it
2017 Dec 04
0
Dynamic reference, right-hand side of function
Loops are not evil, and no-one in this thread said they are. But I
believe your failure to provide a reproducible example is creating
confusion, since you may be using words that mean one thing to you and
something else to the readers here.
################################
# A reproducible example includes a tiny set of sample data
# Since we cannot reproducibly refer to filenames (your
2017 Dec 05
0
Dynamic reference, right-hand side of function
By the way, R 'vectors' are not the equivalents of mathematical 'vectors'.
In R, a vector is something that can have arbitrary length and which has
no 'attributes', other than perhaps element names. Vectors can be numeric,
character,
complex, lists, etc. Functions, names, and NULL are not vectors. In my
opinion,
the typical data scientist will rarely find the R vector
2010 Feb 26
3
Preserving lists in a function
Dear R users,
A co-worker and I are writing a function to facilitate graph plotting in R. The function makes use of a lot of lists in its defaults.
However, we discovered that R does not necessarily preserve the defaults if we were to input them in the form of list() when initializing the function. For example, if you feed the function codes below into R:
myfunction=function(
list1=list
2012 Dec 04
3
do.call
Hello,
I have a problem with the "do.call-function". I would like to merge
the values of more than 30 columns, but not in all of the rows exist
values, so with this commando i get a lot of ";" or NA.
How get i only the merge of cells with a number?
datos$NEW <- do.call(paste, c(datos[,19:53], sep = ";"))
$ NEW : chr
2003 Feb 08
3
to modify a matrix
Hi All.
I am quite a newbie to R.
This is a next basic question.
I have a matrix;
> x <- matrix(1:10.,5)
> x
[,1] [,2]
[1,] 1 6
[2,] 2 7
[3,] 3 8
[4,] 4 9
[5,] 5 10
I like to get a modified matrix as follows;
[,1] [,2]
[1,] 1 6
[2,] 2 7
[3,] 3 8 * 5 -> 40
[4,] 4 9
[5,] 5 10
The following expression does not work.
2009 Oct 30
2
Names of list members in a plot using sapply
Hi R users:
I got this code to generate a graphic for each member of a lists.
list1<-list(A=data.frame(x=c(1,2),y=c(5,6)),B=data.frame(x=c(8,9),y=c(12,6)))
names1<-names(list1)
sapply(1:length(list1),function(i)
with(list1[[i]],plot(x,y,type="l",main=paste("Graphic of",names1[i]))))
Is there a more elegant solution for not to use two separate lists?
I would like to
2011 Jan 08
3
Question on list objects
Hi, I have 2 questions on list object:
1. Suppose I have a matrix like:
dat <- matrix(1:9,3)
Now I want to replicate this entire matrix 3 times and put entire result in a list object. Means, if "res" is the resulting list then I should have:
res[[1]]=dat, res[[2]]=dat, res[[3]]=dat
How can I do that in the easilest manner?
2. Suppose I have 2 list objects:
list1 <- list2
2009 Dec 07
3
Regular expression help
Hi there
I have a string like this i want to extract 9831019 from this string i used
a regular expresion \d+ by which i can only make it to see 7 and returns.
This type of number(9831019) appears in any part of the string and is
definitely more than 5 digits all the time and i want to give that as a
condition
UV7C11-F9-E1 MCS#9831019
MCS Lot #9512516"
how do i go abt it
Ramya
--
View