similar to: R extract parts

Displaying 20 results from an estimated 300 matches similar to: "R extract parts"

2012 Apr 06
4
Order sapply
Good Afternoon, I have the following code, but it seems that something must be doing wrong, because it is giving the results I want. The idea is to create segments while the value of Commutation is less than 1000. for example, from the small set of data below text=" val_user pos v v_star v_end commutation v_source v_destine 1 1 96-96 1173438391 1173438391 0
2018 May 19
0
Split a data.frame
Hello, Maybe something like the following. splitDF <- function(data, col, s){ n <- nrow(data) inx <- which(data[[col]] %in% s) lapply(seq_along(inx), function(i){ k <- if(inx[i] < n) (inx[i] + 1):(inx[i + 1]) data[k, ] }) } splitDF(DF, "name", split_str) Hope this helps, Rui Barradas On 5/19/2018 12:07 PM, Christofer Bogaso
2018 May 19
5
Split a data.frame
Hi, I am struggling to split a data.frame as will below scheme : DF = data.frame(name = c('a', 'v', 'c'), val = 0); DF split_str = c('a', 'c') Now, for each element in split_str, R should find which row of DF contains that element, and return DF with all rows starting from next row of the corresponding element and ending with the preceding value of the
2012 Jul 24
3
Collapsing a vector/data-frame based on the previous values
Hello I have a data frame like this: dput(states) structure(list(Date = c("24/07/2012", "25/07/2012", "26/07/2012", "27/07/2012", "28/07/2012", "24/07/2012", "25/07/2012", "26/07/2012", "27/07/2012", "28/07/2012"), State = c(1L, 1L, 1L, 1L, 1L, -1L, -1L, -1L, 1L, -1L)), .Names = c("Date",
2010 Jul 07
2
What does `_data` mean in transform()?
Hi All, I meant to take the min row by row. But the result is apparently not what I want. Changing min to pmin solve the problem. > df=data.frame(X=1:10, Y=1:10) > transform(df, Z=min(X,10-Y)) X Y Z 1 1 1 0 2 2 2 0 3 3 3 0 4 4 4 0 5 5 5 0 6 6 6 0 7 7 7 0 8 8 8 0 9 9 9 0 10 10 10 0 I try to look at the source code to understand what transform() does. I know
2023 Mar 02
1
transform.data.frame() ignores unnamed arguments when no named argument is provided
Dear r-devel, See below: transform(data.frame(a = 1), 2, 3) #> a #> 1 1 transform(data.frame(a = 1), b=2, 3) #> a b X3 #> 1 1 2 3 We need a small modification to make it work consistently, see below: transform.data.frame <- function (`_data`, ...) { e <- eval(substitute(list(...)), `_data`, parent.frame()) tags <- names(e) ## NEW LINE
2012 Aug 21
2
Sequence detection longer than a certain value
Hello, I have 2 variable: one is an "id" sequence from 1:1000 and the other is variable with real values "VI" from -15.0 to 20.0 and I want to detect id values that have indicator values less than a certain threshold, for example (x=1) BUT that are in sequence equal or longer than 5. For instance, in the following column I want to recognize the sequence from "id" 4
2010 Aug 10
3
grep problem decimal points looping
Hi R Users, I have been trying to work out how to rename column names using grep, basically I have generated these column names using tapply: [1] "NAME" "X1.1" "X2.1" "X3.1" "X4.1" "X5.1" "X6.1" "X7.1" "X8.1" [10] "X1.2" "X2.2" "X3.2" "X4.2"
2012 Aug 10
2
Regular Expressions + Matrices
Hi all, My code looks like the following: inname = read.csv("ID_error_checker.csv", as.is=TRUE) outname = read.csv("output.csv", as.is=TRUE) #My algorithm is the following: #for line in inname #if first string up to whitespace in row in inname$name = first string up to whitespace in row + 1 in inname$name #AND ID in inname$ID for the top row NOT EQUAL ID in inname$ID for the
2018 May 22
4
remove rows of a matrix by part of its row name
Dear R-experts, How can I remove a certain feature or observation by a part of its name. To be clear, I have a matrix with 766 observations as a rows. The row names are like this 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 Now I would like to remove all the rows that contain the text 73.1 Any ideas or suggestion please ? Regards ********************** Ahmed Serag Analytical
2012 Apr 27
6
Returning the coef from two coordinates
Thank you to everyone in this forum that has been helping me with the basic R skills while I learn to apply them. I would like to take the coefficient of two coordinates. One of them comes from two different columns in a table: >A x y a 1 3 b 2 2 c 3 1 the other is set and for this question I'll just call it (1,1) I've been trying to find a way to return the
2012 Sep 23
3
Confused by code?
x<-matrix(c(1,0,0,0,1,0,0,0,1),nrow=3) > y<-matrix(c(0,0,0,1,0,0,1,1,0),nrow=3) > z<-matrix(c(0,1,0,0,1,0,1,0,0),nrow=3) > x[z]<-y[z] The resultant matrix x is all zeros except for the last two diagonal cells which are 1's. While y is lower triangualr 0's with the remaining cells all ones. I really don't understand how this deceptively simple looking piece of
2012 Aug 01
1
Error message: $ operator is invalid for atomic vectors
HI, The code was working perfectly fine yesterday and today, until half an hour ago.? Couldn't find any problems in the code. Still, I am getting error message. myMatrix <- data.matrix(read.table(text=" Name??????????? Age ANTONY??????? 27 IMRAN????????? 30 RAJ????????????????? 22 NAHAS????????? 32 GEO??????????????? 42 ", header=TRUE)) MinMaxArray? <- data.frame(MIN =
2012 Apr 22
4
How to take ID of number > 7.
I figured out something new that I would like to see if I can do this more easy with R then Excel. I have these huge files with data. For example: DataFile.csv ID Name log2 1 Fantasy 5.651 2 New 7.60518 3 Finding 8.9532 4 Looeka -0.248652 5 Vani 0.3548 With like header1: ID, header 2: Name, header 3: log2 Now I need to get the $ID out who have a &log2 value higher then 7. I
2012 Aug 11
3
replace funcion
Hello everybody, I would like to replace or recode a list of numbers between 1 and 12 (total 100). I have tried to make it with recode, but i have two types of replacements. For 1,2,3,4,11,12 => invierno and for 5,6,7,8,9 and 10 => verano. recode(datos.mx1[,7], "1='invierno'; 2='invierno';
2018 May 22
0
remove rows of a matrix by part of its row name
Hello, Use grep to get the row indices and then subset with a *negative* index to remove those rows. rn <- scan(what = character(), text = " 70/556 71.1/280 72.1/556 72.1/343 73.1/390 73.1/556 ") mat <- matrix(rnorm(6*6), nrow = 6) row.names(mat) <- rn inx <- grep("73\\.", row.names(mat)) new_mat <- mat[-inx, ] new_mat Hope this helps, Rui Barradas On
2012 Jan 06
6
cbind alternate
I have two one dimensional list of elements and want to perform cbind and then write into a file. The number of entries are more than a million in both lists. R is taking a lot of time performing this operation. Is there any alternate way to perform cbind? x = table1[1:1000000,1] y = table2[1:1000000,5] z = cbind(x,y) //hanging the machine write.table(z,'out.txt) -- -------------
2012 Aug 15
3
Subsetting with missing data
Simply put, I want to subset the data frame 'a' where 'y=0'. > a <- as.data.frame(cbind(x=1:10, y=c(1,0,NA,1,0,NA,NA,1,1,0))) > a x y 1 1 1 2 2 0 3 3 NA 4 4 1 5 5 0 6 6 NA 7 7 NA 8 8 1 9 9 1 10 10 0 > names(a) [1] "x" "y" > table(a$y) 0 1 3 4 > table(a$y, useNA="always") 0 1 <NA> 3 4
2018 May 22
0
remove rows of a matrix by part of its row name
Hello, Please always cc the list. As for the question, yes, it does. If you want to remove just the ones with exactly 73.1 use the pattern grep("^73\\.1$", etc) Explanation: Beginning of string: ^ End of string: $ Escape special characters: \\ (needed because the period is a special character.) Hope this helps, Rui Barradas On 5/22/2018 12:50 PM, Ahmed Serag wrote: > Thank
2012 Mar 20
1
Remove individual rows from a matrix based upon a list
Dear All, Thanks in advance for any help. I have a square matrix of measures of interactions among individuals and would like to calculate a values from a function (colSums for example) with a single individual (row) excluded in each instance. That individual would be returned to the matrix before the next is removed and the function recalculated. I can do this by hand removing rows based upon