similar to: How to parse text file into a table?

Displaying 20 results from an estimated 10000 matches similar to: "How to parse text file into a table?"

2009 Mar 24
3
Summarizing each row into a frequency table
I have a matrix containing -1, 0, 1, however certain rows will not have all 3 numbers. I have written some codes to compute the frequency table of how many -1s, 0s, 1s per row, but it is very ugly and not efficient if there are more than 3 numbers. Please suggest. m <- rbind(sample(0:1, replace=T, 10), sample(-1:1, replace=T, 10)) m.table <- t(apply(m, 1, function(x) c(sum(x==-1, na.rm=T),
2009 Feb 22
2
How to reshape this data frame from long to wide ?
I tried cast and melt in reshape package, but still can't convert this data frame m m [,1] [,2] [1,] "A" "1" [2,] "A" "2" [3,] "B" "3" to this form. m1 [,1] [,2] [1,] "A" "B" [2,] "1" "3" [3,] "2" NA Please help. [[alternative HTML version deleted]]
2009 Mar 14
2
gsub and regex to tidy comma-limited values
I am cleaning up comma-limited values, so that only one comma separates each value. Using the example below, as much as I try with regex, I can't remove the last comma. I hope to have a one-liner solution, if possible. gsub("^,*|,*$|(,)*", "\\1", ",,,apple,,orange,,,,,lemon,strawberry,,,,") [1] "apple,orange,lemon,strawberry,"
2009 Apr 08
1
Colour each letter of a text string in a plot
I am inserting a DNA sequence into a plot, and hope to colourize each of the four nucleotide of the DNA sequence with a unique colour i.e., A ("red"), C ("green"), G ("blue", and T ("yellow"). I use the following codes, but the DNA sequence only shows as "red" DNA <- "ACGT" plot(1, xlim = c(0,1), ylim = c(0,1), axes=F,
2009 Mar 24
2
Legend containing maths symbol and values of variables
I need to have the maths symbol for >= in the legend, and to substitute threshold variable with its value. Somehow, various attempts weren't successful. Please help. threshold <- 0.5 plot(NA, xlab="", ylab="", main="", axes=F, xlim=c(0,1), ylim=c(0,1), xaxs="i", yaxs="i") legend(x=0, y=1, fill=c("orange", "white",
2009 Apr 22
1
Subsetting a vector of numerics such that standard deviation is less than 0.5 ?
> set.seed(999) > abs(rnorm(20)) [1] 0.28174016 1.31255963 0.79518398 0.27007049 0.27730642 0.56602374 1.87865826 1.26679114 0.96774968 1.12100936 1.32546371 0.13397739 0.93874945 [14] 0.17253810 0.95765045 1.36268625 0.06833513 0.10065765 0.90134475 2.07435711 > v <- abs(rnorm(20)) > v [1] 1.2285633 0.6430443 0.3597629 0.2940356 1.1252685 0.6422657 1.1067376 0.8848404 1.5540951
2009 Feb 22
2
Convert a list to matrix
I would like to convert a list to matrix. This can be easily achieved via do.call. The only problem is each element of the list has different length, which causes the recycling of values. How can I have NA instead of recycled values ? m <- list() m[["A"]] <- 1 m[["B"]] <- 2:3 do.call(rbind, m) [,1] [,2] A 1 1 B 2 3 [[alternative HTML version deleted]]
2009 Mar 23
1
Capitalizing first letter of word or phrase
I managed to find toupper() which translates all letters to uppercase. Is there a function to capitalize only the first letter of word or phrase ? Thanks
2009 Feb 28
2
Review my upgrade plan from 2.8.0 to 2.8.1
Hi, On my laptop, R is installed on windows XP SP2 at D:\Program Files\R\R-2.8.0, and all add-on packages are installed at D:\Program Files\R\R-2.8.0.libs. In addition, I have created two environment enviroment to ease upgrading and installation of packages. Packages installed is a mix of those from CRAN, Bioconductor and local zips. D:\My Document\My Desktop>echo %R_HOME% D:/Program
2010 Feb 15
1
error message in endseq
Hi there, I am new to R and feel so bloody stupid. Abut in spite of a search of several hrs I could not find an answer to my problem. I have imported SPSS data to R, and apart from some warnings regarding duplicate labels, everything looks fine and names lists all my variables. Then I try to run a seqdef command - and get the error message below: > fam.seq<- seqdef(family_seq, var= c
2012 Jul 23
2
Creating panel data
I'm new to R. I am trying to create panel data with a slight alteration from a typical dataset. At present, I have data on a few hundred people with the dates of occurrences for several events (like marriage and employment). The dates are in year/quarter format, so 68.0 equals the 1st quarter of 1968 and 68.25 equals the 2nd quarter of 1968. If the event never occurred,
2008 Jul 08
4
Can R do this ?
I have a folder full of pngs and jpgs, and would like to consolidate them into a pdf with appropriate title and labels. Can this be done via R ? _________________________________________________________________ Easily publish your photos to your Spaces with Photo Gallery. [[alternative HTML version deleted]]
2008 Jun 19
4
Any simple way to subset a vector of strings that do contain a particular substring ?
For example, strings <- c("aaaa", "bbbb","ccba"). How to get "aaaa", "bbbb" that do not contain "ba" ? _________________________________________________________________ [[alternative HTML version deleted]]
2008 Jul 15
5
counting number of "G" in "TCGGGGGACAATCGGTAACCCGTCT"
Any better solution than this ? sum(strsplit("TCGGGGGACAATCGGTAACCCGTCT", "")[[1]] == "G") _________________________________________________________________ [[alternative HTML version deleted]]
2008 Jul 31
4
Identifying common prefixes from a vector of words, and delete those prefixes
For example, c("dog.is.an.animal", "cat.is.an.animal", "rat.is.an.animal"). How can I identify the common prefix is ".is.an.animal" and delete it to give c("dog", "cat", "rat") ? Thanks _________________________________________________________________ [[alternative HTML version deleted]]
2005 Apr 19
1
How to make combination data
Dear R-user, I have a data like this below, age <- c("young","mid","old") married <- c("no","yes") income <- c("low","high","medium") gender <- c("female","male") I want to make some of combination data like these, age.income.dat <- expand.grid(age,
2024 Aug 02
2
grep
Good Morning. Below I like statement like j<-grep(".r\\b",colnames(mydata),value=TRUE); j with the \\b option which I read long time ago which Ive found useful. Are there more or these options, other than ? grep? Thanks. dstat is just my own descriptive routine. > x ?[1] "age"????????? "sleep"??????? "primary"????? "middle" ?[5]
2024 Aug 02
1
grep
?s 02:10 de 02/08/2024, Steven Yen escreveu: > Good Morning. Below I like statement like > > j<-grep(".r\\b",colnames(mydata),value=TRUE); j > > with the \\b option which I read long time ago which Ive found useful. > > Are there more or these options, other than ? grep? Thanks. > > dstat is just my own descriptive routine. > > > x > ?[1]
2013 Oct 04
2
pregunta
En el libro EPICALC (pagina 229-230) en el que está el siguiente script, todo nos funciona bien, pero cuando vamos a life table, ya allí no avanza, lo señalamos en el script, por favor quizá se nos haya ido algún detalle, pero fuimos siguiéndolo por el libro paso a paso y no no hemos percatado Todos los de el paquete survival de la ayuda del R funcionan perfectamente
2005 Dec 20
1
Help to find only one class and differennt class
Dear R users, I have a problem, which I can not find a solution. Probably someone could help me? I have a result from my classification, like this > credit.toy [[1]] age married ownhouse income gender class 1 20-30 no no low male good 2 40-50 no yes medium female good [[2]] age married ownhouse income gender class 1 20-30 yes yes high male