similar to: Determining the length of unique items in a vector

Displaying 20 results from an estimated 7000 matches similar to: "Determining the length of unique items in a vector"

2010 Apr 09
3
NAs are not allowed in subscripted assignments
I'm trying to assign NAs to values that satisfy certain conditions (more complex than shown below) and it gives the right result, but breaks the loop having done the first one viz: new<-c(rep(5,4),6) for (i in 1:6) {new[new[i]>5.5][i]<-NA} gives the correct result, though an error message appears which causes a break if it's in a loop. If I can get rid of the error message and
2018 May 11
0
add one variable to a data frame
Sarah's solutions are good, and here's another, even more basic: tmp1 <- unique(dat1$B) tmp2 <- seq_along(tmp1) dat1$C <- tmp2[ match( dat1$B, tmp1) ] > dat1 N B C 1 1 29_log 1 2 2 29_log 1 3 3 29_log 1 4 4 27_cat 2 5 5 27_cat 2 6 6 1_log 3 7 7 1_log 3 8 8 1_log 3 9 9 1_log 3 10 10 1_log 3 11 11 3_cat 4 12 12 3_cat 4 As a single line
2018 May 11
3
add one variable to a data frame
Hi Sarah, Thank you so much!! I got your good ideas. Ding -----Original Message----- From: Sarah Goslee [mailto:sarah.goslee at gmail.com] Sent: Friday, May 11, 2018 11:40 AM To: Ding, Yuan Chun Cc: r-help mailing list Subject: Re: [R] add one variable to a data frame [Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or
2018 May 11
0
add one variable to a data frame
Hi, Here's one way to approach it, using the coercion of factor to numeric. Note that I changed your data.frame() statement to avoid coercing strings to factors, just to make it simpler to set the levels. dat1 <-data.frame(N=seq(1, 12,1), B=c("29_log","29_log", "29_log", "27_cat", "27_cat", "1_log", "1_log",
2010 Jun 15
1
Problem with the recode function
Hello, I am using the recode() function in Rcmdr and the result is not what I expect so I am almost sure I did something wrong but what... > test <- data.frame(x=1:10) > library(car) > recode(test$x,'1:5=0 ; else=1', as.factor.result=TRUE) [1] 0 0 0 0 0 1 1 1 1 1 Levels: 0 1 BUT > library(Rcmdr) # recode from the car package is now masked Now I recode test$x
2018 May 11
2
add one variable to a data frame
Sarah et. al.: As a matter of aesthetics (i.e. my personal ocd-ness) I prefer using the public API of an object, i.e. *not* to makes use of the representation of a factor as essentially an integer vector with labels, but rather to use its documented behavior. (Feel free to ignore this remark!) Anyway, >cumsum(!duplicated(dat1$B)) [1] 1 1 1 2 2 3 3 3 3 3 4 4 will do it. This is very
2018 May 11
3
add one variable to a data frame
Hi All, I have a data frame dat1: dat1 <-data.frame(N=seq(1, 12,1), B=c("29_log","29_log", "29_log", "27_cat", "27_cat", "1_log", "1_log", "1_log", "1_log", "1_log",
2007 Sep 24
3
CallerID problem Asterisk 1.4.2
When receiving inbound calls from a Vonage Softphone extension, I'm unable to view/maniupulate calledid data. but it shows up in the CDR records and on called handsets.. any ideas? exten => asda,n,NoOp(callerID is ${CALLERID}) exten => asda,n,NoOp(CallerID is ${CALLERIDNAME}) exten => asda,n,NoOp(CallerID is ${CALLERIDNUM}) -- Executing [asd at pstn-in:2]
2010 Mar 10
2
How to sum a list of matrices ?
Dear list, I have a list of three matrices : i = list(matrix(1:4,2,2), matrix(3:6,2,2), matrix(9:12,2,2)) I would like to sum the matrices, as follows : [,1] [,2] [1,] 13 19 [2,] 16 22 I used this code : k <- i[[1]] for (j in (2:length(i))) { k <- k + i[[j]]} But, is it possible to sum without a loop ? Thanks in advance, Carlos [[alternative HTML version deleted]]
2010 Apr 09
1
terminating function
Hi everyone, I 'm building a function, in the middle it controls the sign of a variable x. If x < 0 the function write a warning (Error: negative value!). At this point I want the function stops without execute the remaining code. How can I do to terminate the function before your ending? Thanks in advance. Paolo
2011 Jan 10
1
Using combn
Dear list, I want to apply the "table" function to every pair of variables in df and the return should be a list. setwd(123) asd <- data.frame(a1=sample(1:4, 20, replace=TRUE), a2=sample(1:4, 20, replace=TRUE), a3=sample(1:4, 20, replace=TRUE), a4=sample(1:4, 20, replace=TRUE)) with(asd, table(a1, a2)) with(asd, table(a1,
2014 Jul 17
2
question about output of files copied/deleted
It seems to me that this output would be more useful if it were possible to uniquely translate a line of output back into a file path. Right now that's not possible due to the control character encoding. An output line like asd\#002\#003zxc could either mean a file of that name or asd^B\#003zxc or asd^B^Czxc or asd\#002^Czxc I was hoping to start with rsync -n, figure out what was going to be
2004 Mar 09
1
More factor names in x axis, how?
I have some data which records, amongst other things, age (recoded by me to be in months), and drug group (a factor). The drug group is a 2 digit number, but there is no numeric relationship, and only 50 of the possible groups occur So > asd <- read.table("asd.dat", header=TRUE) > asd$group <- as.factor(asd$group) > plot(age ~ group, data=asd) gives me a series of
2009 Oct 29
1
Question about is.na for missing data
Greetings, I am trying to a simple mean imputation using the following command (yes, I know it is not an ideal way to impute missing data) asd[is.na(asd)] <- mean(asd,na.rm=TRUE) This has worked quite well in the past. Now, however, I am getting the following error messsage. Error in `[<-.data.frame`(`*tmp*`, is.na(asd), value = c(2433.64150943396, : rhs is the wrong length for
2010 Oct 27
3
Increase R precision
Hello everyone. When I execute the following in R > (18-46)/(45-93) [1] 0.5833333 I get small precision for what I am trying to deal with . Is it possible to increase the precision for this and for other operations? For example openoffice calc for this operation returns 0.58333333333333300000 I I would like to thank you for your help [[alternative HTML version
2011 Jun 06
2
adding an ellipse to a PCA plot
Hi, I created a principal component plot using the first two principal components. I used the function princomp() to calculate the scores. now, I would like to superimpose an ellipse representing the center and the 95% confidence interval of a series of points in my plot (as to illustrate the grouping of my samples). I looked at the ellipse() function in the ellipse package but can't get it
2012 Dec 26
3
Working with date
Hi, Let say I have a date variable: > ?asd <- as.Date("2012-01-03") > asd [1] "2012-01-03" Now, I want to express this date like 3/1/2012. can somebody help me how to achieve that? Thanks,
2013 Mar 20
3
Introduction to R. Any such documentation in Vietnamese?
Dear fellow users Are there any Vietnamese language resources for beginners of R? If so, I would be interested in hearing from people who have had experience with them and which are better (if there is more than one). I am involved with an aid project in Vietnam, and would like to move the scientists involved from using Excel for 'analysis' to R. Thanks .... Peter Alspach The
2010 Aug 09
1
Difference Between R: wilcox.test and STATA: signrank
This is my first post to the mailing list and I guess it's a pretty stupid question but I can't figure it out. I hope this is the right forum for these kind of questions. Before I started using R I was using STATA to run a Wilcoxon signed-rank test on two variables. See data below:
2012 Mar 22
3
[LLVMdev] SPEC CPU2006 bitcode files
Hello, I'm trying to generate bitcode files from the SPEC CPU2006 benchmark suites. First I installed the benchmarks into ~/llvm/projects/test-suite/External/speccpu2006 and then I tried ~/mysandbox/bin/lnt runtest nt --sandbox=sandbox --cc=/Users/asd/llvm/Release/bin/clang --test-suite=/Users/asd/llvm/projects/test-suite --test-externals=/Users/asd/llvm/projects/test-suite/External -j 4