use awk to calculate percentage of column 1 derived from column 2 and add it to column 3
Tag : awk , By : Andrew L.
Date : March 29 2020, 07:55 AM
should help you out I have a file consisting out of 2 columns, both contain only whole numbers. I want awk to add a third column which shows the percentage of column 1, derived from column 2. , Another awk awk '$3=100*$1/$2' file
awk '$3=100*$1/$2' file > tmp && mv tmp file
awk '$2>0{$3=100*$1/$2}1' file > tmp && mv tmp file
awk '$2>0&&$3=100*$1/$2' file > tmp && mv tmp file
|
Extract a value in column A given the maximum value in column B within each group (column C) in an R dataframe?
Date : March 29 2020, 07:55 AM
Any of those help My question is related to Extract the maximum value within each group in a dataframe. , Here is a base R and a data.table solution: df <- structure(list(Group = c("A", "A", "B", "B", "B", "C", "D", "D"
), Value = c(12L, 10L, 3L, 5L, 6L, 1L, 3L, 4L), Year = c(1933L,
2010L, 1935L, 1978L, 2011L, 1954L, 1933L, 1978L)), .Names = c("Group",
"Value", "Year"), row.names = c(NA, -8L), class = "data.frame")
# Base R - use aggregate to get max Value per group, then merge with df
merge(df, aggregate(Value ~ Group, df, max), by.all = c("Group", "Value"))[
, c("Group", "Year")]
# Group Year
# 1 A 1933
# 2 B 2011
# 3 C 1954
# 4 D 1978
# data.table solution
library(data.table)
dt <- data.table(df)
dt[, .SD[which.max(Value), .(Year)], by = Group]
# Group Year
# 1: A 1933
# 2: B 2011
# 3: C 1954
# 4: D 1978
|
Extract values for a column from another column based on another column in data frame R
Tag : r , By : Lauren Kirschner
Date : March 29 2020, 07:55 AM
hope this fix your issue If you don't want to have to hard code all of the column names you can use something like this. comp.cols <- colnames(df)[grepl("_comp", colnames(df)) == TRUE]
non.comp.cols <- sub("_comp", "", comp.cols)
df[df[,"reg"] == "a", comp.cols] <- df[df[,"reg"] == "a", non.comp.cols]
|
how to extract column name and column value, by column number of all record from access query and / or table
Date : December 22 2020, 01:30 PM
I wish this helpful for you I am trying to create vba code to generate kml data from access data , got the solution... here's my final code... 'define input box for target table
Dim Message, Title, Default, MyValue
Message = "Enter table/query name" ' Set prompt.
Title = "kmlwriter" ' Set title.
Default = "tablequeryname" ' Set default.
MyValue = inputbox(Message, Title, Default)
'/inputbox
'define writing object for export
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
'define recordset for target table fetch and looping
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [" & MyValue & "]")
'define counter and output
Dim Fileout As Object
Dim i As Integer
'set output directory, replace 'peta' with something for sub directory of your currentdatabase
Set Fileout = fso.CreateTextFile(CurrentProject.Path & "\peta\" & MyValue & ".kml", True, True)
'standard header for kml
Fileout.write "<?xml version=""1.0"" encoding=""UTF-8""?><kml><Document><!-- Begin Style Definitions -->"
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst 'Unnecessary in this case, but still a good habit
Do Until rs.EOF = True
'output name and coordinates, I place those 3 in order, latitude, longitude, point name
Fileout.write vbNewLine & "<Placemark>"
Fileout.write "<Point><altitudeMode>clampToGround</altitudeMode><extrude>0</extrude>"
'rs(0) = latitude, rs(1) = longitude
Fileout.write "<coordinates>" & rs(1) & "," & rs(0) & ",0" & "</coordinates></Point>"
'rs(2) = point name
Fileout.write vbNewLine & "<name>" & rs(2) & "</name><description><![CDATA["
'output description for points
For i = 3 To rs.Fields.Count - 1
Fileout.write "<br><b>" & rs(i).Name & "</b> =" & rs(i)
Next i
Fileout.write "]]></description></Placemark>"
'Move to the next record. Don't ever forget to do this.
rs.MoveNext
Loop
Else
MsgBox "There are no records in the recordset."
End If
'standard kml footer
Fileout.write vbNewLine & "</Document></kml>"
Fileout.Close
'open save directory in mazimized windows
Shell "C:\WINDOWS\explorer.exe """ & CurrentProject.Path & "\peta", vbMaximizedFocus
|
How to compare one column value available or not in another column dataframe and extract another column of second datafr
Tag : python , By : user167963
Date : March 29 2020, 07:55 AM
|