Displaying 7 results from an estimated 7 matches for "new_mats".
2009 Feb 10
2
Problem with retrieving updated variables after attach()
Hello,
suppose I have a data frame:
> mat
id age
1 NA NA
2 NA NA
3 NA NA
4 NA NA
5 NA NA
Then I attach the data frame:
> attach(mat)
I assign some new values...
> id <<- sample(100,5)
> age <<- rnorm(5,mean=30)
Then I want to create a new data frame from the variables id and age which still are attached to position 2 of the R environment...
> new_mat <-
2011 Jun 30
2
volcano plot.r
...ot;, sep=",", row.names=1, header=TRUE)
# Get groups information
groups<-data[,1]
# Get levels for groups
grp_levs<-levels(groups)
if (length(levels(groups)) > 2)
print("Number of groups is greater than 2!") else {
#
# Split the matrix by group
#
new_mats<-c()
for (ii in 1:length(grp_levs))
new_mats[ii]<-list(data[which(groups==levels(groups)[ii]),])
#
# Calculate the means
#
# For each matrix, calculate the averages per column
submeans<-c()
# Preallocate a matrix for the means
means<-matri...
2011 Jun 20
2
(no subject)
...ot;, sep=",", row.names=1, header=TRUE)
# Get groups information
groups<-data[,1]
# Get levels for groups
grp_levs<-levels(groups)
if (length(levels(groups)) > 2)
print("Number of groups is greater than 2!") else {
#
# Split the matrix by group
#
new_mats<-c()
for (ii in 1:length(grp_levs))
new_mats[ii]<-list(data[which(groups==levels(groups)[ii]),])
#
# Calculate the means
#
# For each matrix, calculate the averages per column
submeans<-c()
# Preallocate a matrix for the means
means<-matri...
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
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
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
2011 Jun 30
0
help with interpreting what nnet() output gives:
...ot;, sep=",", row.names=1, header=TRUE)
# Get groups information
groups<-data[,1]
# Get levels for groups
grp_levs<-levels(groups)
if (length(levels(groups)) > 2)
? ? print("Number of groups is greater than 2!") else {
? ? #
? ? # ? ?Split the matrix by group
? ? #
? ? new_mats<-c()
? ? for (ii in 1:length(grp_levs))
? ? ? ? new_mats[ii]<-list(data[which(groups==levels(groups)[ii]),])
? ??
? ? #
? ? # ? ?Calculate the means
? ? #
? ? # For each matrix, calculate the averages per column
? ? submeans<-c()
? ? # Preallocate a matrix for the means
? ? means<-matri...