I tried to use a separate function to make the code more understandable. But
I failed. I don't know what's wrong with the code.
x <- as.matrix(x)
rearrange <- function(.row){
z <- do.call(rbind, strsplit(.row[-1], ''))
z.col <- t(apply(z, 2, paste, collapse=''))
cbind(.ro
To remove NA instead of Total:
rbind(data,cbind(State="Total", t(apply(data[,-1],2,sum
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Re-Adding-column-sum-to-new-row-in-data-frame-tp2223277p2223855.html
Sent from the R help mailing list archive at Nabb
Thank David and Jim.
I got it.
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/sample-and-rearrange-tp747p2223872.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
## Create a function to assign a series of values to a list of objects
## The assign function can only assign one value (could be a vector) to a
name
## Set the environment to be global, otherwise the objects can't be used
outside the function
## List objects that have been created
toto <- functi
I hope this is what you want.
## Exclude replicated rows
(DF1 <- unique(DF))
## Sort the data
(DF2 <- DF1[order(DF1$V1, DF1$V2, DF1$V3, DF1$V4),])
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-extract-rows-from-data-frame-based-on-unique-variable-gro
## Dung observations
## Create a sample original data
data <- data.frame(Species=sample(c("W", "G", "R"), 200, replace=TRUE),
Age=sample(c("days", "weeks", "months"),200,replace=TRUE),
Termites=sample(c(0,1),200,replace=TRUE))
## Show what original data look like
head(data)
Spe
A dummy way is to resequence or rematrix
olddata <- data.frame(matrix(rnorm(200), nrow=40))
newdata <- data.frame(matrix(as.vector(t(olddata)), nrow=nrow(olddata)/10))
dim(olddata)
dim(newdata)
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Concatenation-tp
Sorry, I made a mistake. Should add "byrow = TRUE".
Using randomly created values can't check the result, a sequence will be
better.
olddata <- data.frame(matrix(1:200, nrow=40, byrow = TRUE))
newdata <- data.frame(matrix(as.vector(t(olddata)),
nrow=nrow(olddata)/10,byrow = TRUE))
dim(olddata)
di
I hope this will help.
### Find rows with minimum value from every 5 rows
## Create the data
mlb <- data.frame(mass_position=c(1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20),
mass_value=c(9,2,3,2,5,6,7,8,9,10,2.1,12, 1,14,15,16,17,18,19,20),
mass_label=c("lab1","lab2","lab3","lab4"
Might there be a limit ?
> c <- matrix(1:1, ncol=200)
> dim(c)
[1] 50200
> c <- matrix(1:10, ncol=200)
Error: cannot allocate vector of size 3.7 Gb
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Increasing-the-maximum-number-of-rows-t
?strptime will helps.
> d <- as.Date("01/05/2007","%m/%d/%Y")
> format(d, "%A, %b %d, %Y")
[1] "Friday, Jan 05, 2007"
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/From-date-to-week-day-tp2228954p2228992.html
Sent from the R help mailing list archive at Nab
Do you mean count frequency of One Bedroom?
table(dummy[dummy$Bedroom==1,][,1:2])
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/help-required-to-melt-a-data-frame-tp2229633p2230260.html
Sent from the R help mailing list archive at Nabble.com.
__
Hope it helps this time:)
### Package reshape, function melt and cast
### Read table
dummy <- read.table(textConnection("State Months Bedroom
1xxxJan 1
2xxxJan 2
3xxxJan 1
4yyyJan 1
5yyyJan 2
6yyyJan 1
7zzz
I can only repeat your error message :)
> n256 <- paste(rep("A",256),collapse="")
> assign(n256, 1)
> n257 <- paste(rep("A",257),collapse="")
> assign(n257, 1)
Error in assign(n257, 1) : variable names are limited to 256 bytes
-
A R learner.
--
View this message in context:
http://r.7896
### Special cumsum
### Do cumsum when TRUE, and reset to 0 when FALSE
x <- c( TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE )
## The rle function computes the lengths of equal values of a vector
## And gives two vecters: $lengths and $values
## The sequence function creates and concaten
I don't know if my understanding of P is right.
P ?= (the number of lives at the end of the interval)/(the number of lives
at the beginning of the interval)
### Compute proportion of a cohort that survives through the interval
### The formula is P0=L1/LO
## Original data is a vector of death da
Thank you very much David. I'm sorry for this fault , hope it has not
confused Frostygoat.
I was clueless of recursive reference and I didn't meet any error when I
test the code. So I wonder if there are some useful tips to prevent making
this kind of faults:)
The revised code is followed.
###
Do you mean replace values of a column?
> df <- data.frame("Jan" = 1:3,"Feb" = 11:13)
> df
Jan Feb
1 1 11
2 2 12
3 3 13
> df$Jan <- 21:23
> df
Jan Feb
1 21 11
2 22 12
3 23 13
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/Re-help-to-replace-
Hope it helps.
text <- "var1var2
9G/G09abd89C/T90
10A/T932C/C
90G/G A/A"
x <- read.table(textConnection(text), header = T)
x$var1.1 <- sub(".*(.)/.*", "\\1", x$var1)
x$var1.2 <- sub(".*/(.).*", "\\1", x$var1)
x$var2.1 <- sub(".*(.)/.*", "\\1", x$var2)
x$var2.2 <- sub(".*/(.
Try unique and paste.
paste(unique(tes)[,1], unique(tes)[,2], sep = "")
-
A R learner.
--
View this message in context:
http://r.789695.n4.nabble.com/two-columns-into-one-tp2242516p2242658.html
Sent from the R help mailing list archive at Nabble.com.
__
Please try this
## Import data
id1<-c(4,17,9,1,1,1,3,3,6,15,1,1,1,1,3,3,3,3,4,4,4,5,5,12,9,9,10,10)
id2<-c(8,18,10,3,6,7,6,7,7,16,4,5,12,18,4,5,12,18,5,12,18,12,18,18,15,16,15,16)
id<-data.frame(id1 = id1, id2 = id2)
## Create same structure table
id <- id0 <- unique(id)
leng <- nrow(id)
n <- 0
101 - 121 of 121 matches
Mail list logo