[R] extract values

Sarah Goslee sarah.goslee at gmail.com
Tue Mar 12 19:04:07 CET 2013


Data in x is never > 1820:
> summary(x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
 0.8465  1.2890  1.5660  1.5710  1.8050  3.4340

And your object is a vector: trying to extract the first column with
x[,1] is meaningless, because x has no dimensions.
> dim(x)
NULL

It looks to me as if you want to extract values of x where the *names*
are > 1820, but the names are character, so maybe:

x1 <- x[as.numeric(names(x)) > 1820]

is what you're looking for.

Sarah

On Tue, Mar 12, 2013 at 1:50 PM, catalin roibu <catalinroibu at gmail.com> wrote:
> Hello all!
> I have a problem to extract values greater that for example 1820.
> I try this code: x[x[,1]>1820,]->x1
> Please help me!
>
> Thank you!
>
> The data structure is:
> structure(c(2.576, 1.728, 3.434, 2.187, 1.928, 1.886, 1.2425,
> 1.23, 1.075, 1.1785, 1.186, 1.165, 1.732, 1.517, 1.4095, 1.074,
> 1.618, 1.677, 1.845, 1.594, 1.6655, 1.1605, 1.425, 1.099, 1.007,
> 1.1795, 1.3855, 1.4065, 1.138, 1.514, 1.4605, 1.756, 1.4165,
> 1.22, 1.825, 1.8365, 1.81, 1.818, 2.1085, 2.233, 2.5605, 2.285,
> 2.821, 2.16, 1.914, 1.747, 2.031, 1.847, 1.7715, 1.7925, 1.651,
> 1.4345, 1.291, 1.9895, 1.99, 1.73, 1.912, 1.776, 1.596, 1.6915,
> 1.8245, 1.773, 2.173, 2.2345, 2.105, 1.922, 1.802, 1.6385, 1.6545,
> 2.1785, 1.868, 2.1855, 2.5175, 2.025, 2.435, 1.809, 1.628, 1.327,
> 1.3485, 1.4335, 2.052, 2.2465, 2.151, 1.7945, 1.79, 1.6055, 1.616,
> 1.633, 1.665, 2.002, 2.152, 1.736, 1.7985, 1.9155, 1.7135, 1.548,
> 1.568, 1.713, 2.079, 1.875, 2.12, 2.072, 1.906, 1.4645, 1.3025,
> 1.407, 1.5445, 1.437, 1.463, 1.5235, 1.609, 1.738, 1.478, 1.573,
> 1.0465, 1.429, 1.632, 1.814, 1.933, 1.63, 1.482, 1.466, 1.4025,
> 1.6055, 1.279, 1.827, 1.201, 1.425, 1.678, 1.5535, 1.599, 1.826,
> 1.964, 1.68, 1.492, 1.509, 1.666, 1.5665, 1.666, 1.4885, 1.8205,
> 1.5965, 1.84, 1.551, 1.4835, 1.805, 1.7145, 1.902, 1.2085, 0.9095,
> 0.9325, 1.34, 1.6135, 1.5825, 1.757, 1.7105, 1.3115, 1.288, 1.567,
> 1.7795, 1.642, 1.4375, 1.4495, 1.4225, 1.4885, 1.251, 1.179,
> 1.188, 1.3605, 1.373, 1.2185, 1.405, 1.016, 0.979, 1.018, 1.0335,
> 1.39, 1.3005, 1.3955, 1.301, 1.6475, 1.1945, 1.3215, 1.0535,
> 1.1645, 1.0895, 1.041, 1.155, 1.322, 1.1615, 0.933, 1.1215, 1.022,
> 0.922, 0.8465, 1.103, 1.1375, 1.23, 1.289, 1.222, 1.4865, 1.4025,
> 1.4295, 1.156, 0.9085, 0.8755, 0.9135, 0.982, 1.145, 1.1295,
> 1.3475, 1.2415, 1.2505), .Names = c("1799", "1800", "1801", "1802",
> "1803", "1804", "1805", "1806", "1807", "1808", "1809", "1810",
> "1811", "1812", "1813", "1814", "1815", "1816", "1817", "1818",
> "1819", "1820", "1821", "1822", "1823", "1824", "1825", "1826",
> "1827", "1828", "1829", "1830", "1831", "1832", "1833", "1834",
> "1835", "1836", "1837", "1838", "1839", "1840", "1841", "1842",
> "1843", "1844", "1845", "1846", "1847", "1848", "1849", "1850",
> "1851", "1852", "1853", "1854", "1855", "1856", "1857", "1858",
> "1859", "1860", "1861", "1862", "1863", "1864", "1865", "1866",
> "1867", "1868", "1869", "1870", "1871", "1872", "1873", "1874",
> "1875", "1876", "1877", "1878", "1879", "1880", "1881", "1882",
> "1883", "1884", "1885", "1886", "1887", "1888", "1889", "1890",
> "1891", "1892", "1893", "1894", "1895", "1896", "1897", "1898",
> "1899", "1900", "1901", "1902", "1903", "1904", "1905", "1906",
> "1907", "1908", "1909", "1910", "1911", "1912", "1913", "1914",
> "1915", "1916", "1917", "1918", "1919", "1920", "1921", "1922",
> "1923", "1924", "1925", "1926", "1927", "1928", "1929", "1930",
> "1931", "1932", "1933", "1934", "1935", "1936", "1937", "1938",
> "1939", "1940", "1941", "1942", "1943", "1944", "1945", "1946",
> "1947", "1948", "1949", "1950", "1951", "1952", "1953", "1954",
> "1955", "1956", "1957", "1958", "1959", "1960", "1961", "1962",
> "1963", "1964", "1965", "1966", "1967", "1968", "1969", "1970",
> "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978",
> "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986",
> "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994",
> "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002",
> "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010",
> "2011"))
>


--
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list