logo
down
shadow

create a matrix in Perl or R if data is provided in CSV file


create a matrix in Perl or R if data is provided in CSV file

By : user2175629
Date : October 14 2020, 08:10 PM
hop of those help? This is a CSV file cn0_gene.csv:-
code :
library( data.table )

dt <- fread("./cn0_gene.csv")
dcast( dt, Sample_Name ~ Gene_Names, value.var = "Frequencey" )

#    Sample_Name ACTA2,FAS,FAS-AS1 MMP26,OR51A2 NOT_FOUND OR52N1,OR52N5,TRIM5 RHD,RSRP1 RNLS SCAPER TP63 WWOX
# 1:   gw6.00033                NA           NA         4                  NA        NA   NA     NA   NA   NA
# 2:    gw6.0006                 1            1         5                   1         1    1      1    1    1
dcast( dt, Sample_Name ~Gene_Names, value.var = "Frequencey", fill = 0 )

#    Sample_Name ACTA2,FAS,FAS-AS1 MMP26,OR51A2 NOT_FOUND OR52N1,OR52N5,TRIM5 RHD,RSRP1 RNLS SCAPER TP63 WWOX
# 1:   gw6.00033                 0            0         4                   0         0    0      0    0    0
# 2:    gw6.0006                 1            1         5                   1         1    1      1    1    1


Share : facebook icon twitter icon
How do I read data from txt file to create a 2D matrix?

How do I read data from txt file to create a 2D matrix?


By : HAMNA
Date : March 29 2020, 07:55 AM
wish of those help I am writing a function in R which reads a text file with some header information in the first 8 lines and then the actual data starts. Here is how the file looks: , can't you just create a matrix with 511 lines?
code :
v <- rnorm(511*511, 3, 1)
matrix(v, nrow = 511, ncol = 511)
v<- rnorm(4*4, 3,1)
> matrix(v, nrow = 4, ncol = 4)
         [,1]     [,2]     [,3]     [,4]
[1,] 1.944165 4.263226 2.700559 3.672780
[2,] 3.932594 1.742278 3.733877 3.115301
[3,] 5.224144 1.139828 2.979448 3.402496
[4,] 3.619015 4.248993 2.667306 2.168456

library(raster)
rv <- raster(matrix(v, nrow = 4, byrow = F)) # you'll want it with the default byrow = F
plot(rv)
x y v
0 0 4.169080e+000
1 0 6.391669e+000
2 0 6.391669e+000
511 0 9.922547e+000
0 1 5.268026e+000
1 1 5.268026e+000
511 511 9.922547e+000
v <- read.table(text=readClipboard(), header=T)
> d
    x   y        v
1   0   0 4.169080
2   1   0 6.391669
3   2   0 6.391669
4 511   0 9.922547
5   0   1 5.268026
6   1   1 5.268026
7 511 511 9.922547
v <- matrix(d$v, nrow = 4, byrow = F)
rv <- raster(v, xmn=x@extent@xmin, ymn=x@extent@ymin,
             xmx=x@extent@xmax, ymx=x@extent@ymax,
             crs = CRS(proj4string(x)))
myfolder <- 'D:/temp'
d <- read.table(file.path(myfolder, 'sample.txt'), header = F, skip = 9, sep = '')
> head(d)
  V1 V2 V3
1  0  0 12
2  1  0  7
3  2  0 10
4  3  0 11
5  4  0  8
6  5  0  9
rv <- raster(nrows=100, ncols=100)
rv[] <- matrix(d$V3, nrow = 100, byrow = F)
plot(rv)
rv1 <- raster(matrix(d$V3, nrow = 100, byrow = T), # I'm changing how d$V3 is arranged
              xmn=0, ymn=0,
              xmx=1, ymx=1)
spplot(rv1, scales = list(draw = TRUE))
Create adjacency matrix from char[][] array provided rules

Create adjacency matrix from char[][] array provided rules


By : user3906776
Date : March 29 2020, 07:55 AM
may help you . I want to change a char[][] array (lets call it cA) into an adjacency matrix. An adjacency matrix has columns and rows equal to the number of elements in an array, and each vertex in the adjacency matrix is either true or false depending if the elements in the initial array are adjacent. I want to bend the rules a little and also constrain an adjacency matrix vertex to true iff the elements are adjacent and one of the elements is not a specific value. , Try this:
code :
static void set(boolean[][] aM, int cols, int row0, int col0, int row1, int col1) {
    int index0 = row0 * cols + col0;
    int index1 = row1 * cols + col1;
    aM[index0][index1] = aM[index1][index0] = true;
}

static boolean[][] adjacencyMatrix(char[][] cA) {
    int rows = cA.length;
    int cols = cA[0].length;
    boolean[][] aM = new boolean[rows * cols][rows * cols];
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            if (cA[i][j] == 'y')
                continue;
            if (i + 1 < rows && cA[i + 1][j] != 'y')
                set(aM, cols, i, j, i + 1, j);
            if (j + 1 < cols && cA[i][j + 1] != 'y')
                set(aM, cols, i, j, i, j + 1);
        }
    }
    return aM;
}

public static void main(String[] args) {
    char[][] cA = {
        {'z', 'y', 'z'},
        {'z', 'z', 'z'},
        {'z', 'y', 'y'},
    };
    boolean[][] aM = adjacencyMatrix(cA);
    for (boolean[] row : aM) {
        for (boolean cell : row)
            System.out.print(cell ? "1" : "0");
        System.out.println();
    }
}
000100000
000000000
000001000
100010100
000101000
001010000
000100000
000000000
000000000
create a matrix with four column and 5 rows using the sample provided in python

create a matrix with four column and 5 rows using the sample provided in python


By : Ben Ninjjaa Arnold
Date : March 29 2020, 07:55 AM
it fixes the issue ummm put those 5 lists a, b, c, d, e in a list call matrix
matrix = [a,b,c,d,e] then you get a matrix.
How to create matrix from data in a text file MATLAB?

How to create matrix from data in a text file MATLAB?


By : joshi
Date : March 29 2020, 07:55 AM
wish help you to fix your issue You can read the file using readmatrix. First, you can specify some import options with delimitedTextImportOptions. For your particular example, it is sufficient to specify that the data starts at line 4, and that you want to join delimiters (spaces).
code :
opts = delimitedTextImportOptions('DataLines',4, 'Delimiter', ' ', 'ConsecutiveDelimitersRule', 'join')
A = readmatrix('yourfile.txt', opts) % results in cell array, due to mixed numbers and strings
data_of_interest = str2double(A(:,end-5:end));
Perl Win32 - Geting file handle provided file and removing it

Perl Win32 - Geting file handle provided file and removing it


By : droidGeek
Date : March 29 2020, 07:55 AM
this one helps. It is possible to locate which process hold a file handle open and to reach into the process and kill the handle because MS's Process Explorer can do just this. How? I don't know.
You should probably use MoveFileEx(file_name, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) instead. This causes the file to be deleted the next time the system is rebooted.
Related Posts Related Posts :
  • Authentication failure with rdrop2
  • DT data table display error
  • Issue when adding new rows (with nested dataframes within) to a dataframe
  • R-How to compare two dataframe and update list column value
  • Series vector for approximating pi
  • what is difference between "variance explained " in Random Forest and "merror" in XGBoost
  • R - Cast dataframe on unique rows - reshape2
  • ggplot2: plot correct proportions using geom_bar
  • Speedup query for R data.table - can this two-argument function be applied by group more quickly?
  • apply a function to several columns at once with mutate
  • R 'cowplot' neatly produce gridded plot with shared (common) legends and unique legends
  • Repeat R script for many times and save results to text file
  • How to negative lookbehind for special characters
  • data.table inner join produces error when no match is found
  • Create a new column base on existing column, but row above
  • Is there a way to visualize the process of source() in RStudio?
  • google places api consumes 10 request but I am doing only 1
  • Statistical mode of a categorical variable in R (using mlv)
  • Using for-loop to mutate a data.frame in r
  • Make plot with regression line for mixed model
  • Shortcut to select matces cases in R studio
  • vectoriced norm/matrix multiplication
  • Negative log10 transformation in R
  • Plot data with duplicate points
  • Visualizing crosstab tables with a plot in R - changing colours
  • How to manually modify automated numbers and labels in plot
  • How can I follow any redirections of a url in R?
  • Add jitter to box plot using markers in plotly
  • Adding an extra item to the legend
  • ggplot fills in data in the wrong order
  • Convert list to data frame
  • R: filtering by list(s) of strings and returning all results that start with the content of the lists
  • R:How to attach parts of a data frame with different headers and/or an overflowing piece of the dat frame
  • How to use 'par' for manipulating plot margins?
  • Can dplyr::case_when return mix of NAs and non-NAs?
  • Text preprocessing and topic modelling using text2vec package
  • Uploading multiple files in Shiny, process the files, rbind the results and return a download
  • R levelplot: color green-white-red (white on 0) according to one variable, but show the values of another variable
  • Why [i] doesn't point to the starting point in a vector
  • In R after generating a mvrnorm distribution, Y, what does Y[,1] do?
  • expand a data frame to have as many rows as range of two columns in original row
  • Getting started with R and CFA
  • Re order x-axis in ggplot so time goes from 12AM to 11PM in R
  • R - Automatically stack every nth column of a data frame and save them as new objects
  • How to format dplyr output in R into doubles (or other workable format)?
  • Dataframe to matrix conversion using tapply turns zeros to NAs
  • Smallest multiple of 1:20 - How can I make it quicker?
  • How to specify the size of a graph in ggplot2 independent of axis labels
  • How can I find the number of a vector's elements in another vector?
  • ROC curve from train/test set in caret R package
  • Random Forest for a mixture of categorical,numeric and "unwanted" variables which include missing values
  • extract certain data from multiple excel files with R
  • Matrix with counts of wins and losses between methods in R
  • Grouping string variables from a dataframe by best string match to make subsets
  • Reorder does not work after adding second geom_points
  • cover POS data formate to the one can apply Arules (Apriori)
  • Matching values between data frames based on overlapping dates
  • Grouped bar chart turns into stacked bar chart ggplot
  • R: How to fill in NA Values within a Column based on grouping?
  • Two action buttons, but only the first one, that is written in the server file, works?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org